1. 程式人生 > >QCad原始碼分析 第二章

QCad原始碼分析 第二章

       QCad中通過c++程式碼與js程式碼結合的方式開發,C++用於功能的開發,js用於邏輯的處理,啟用通過RScriptHandler類將c++類匯出為指令碼可呼叫的介面。

指令碼相關的類的關係如下圖:

 

 

 

      RScriptHandlerRegistry:指令碼註冊類,管理的是指令碼的檔名與指令碼建立函式的對映表QMap<QString, RScriptHandlerRegistry::FactoryFunction> RScriptHandlerRegistry::factoryFunctions和已經載入的指令碼檔案和指令碼解析器的對映表QMap<QString, RScriptHandler*> RScriptHandlerRegistry::globalScriptHandlers;

     RScriptHandler:指令碼抽象類;

     RScriptHandlerEcma:ECMA封裝類,封裝了QScriptEngine指令碼直譯器,用於匯出C++類及相關的介面。

    其中RScriptHandlerEcma類的建構函式中的程式碼解釋如下:

RScriptHandlerEcma::RScriptHandlerEcma() : engine(NULL), debugger(NULL) {
    //  registerScriptHandler(this, getSupportedFileExtensionsStatic());

    //每個handler對應一個直譯器
    engine = new QScriptEngine();

    //總是允許載入指令碼【如果為true表示可以重複載入同一個指令碼,即可以動態修改指令碼並更新功能】
    alwaysLoadScripts = qApp->arguments().contains("-always-load-scripts");

    // only enable script debugger over command line as expert option.
    // Script debugger can cause crashes.
    //是否啟用指令碼除錯程式
    if (RSettings::isGuiEnabled() && RSettings::isDebuggerEnabled()) {
        qWarning() << "RScriptHandlerEcma::RScriptHandlerEcma: script debugger enabled! Not recommended.";
        //建立一個偵錯程式
        debugger = new QScriptEngineDebugger(engine);
        debugger->setObjectName("debugger");
        debugger->attachTo(engine);
    }
    else {
        //如果不啟用除錯視窗,則用繫結異常處理函式來提示錯誤
        connect(engine, SIGNAL(signalHandlerException(const QScriptValue&)),
                this, SLOT(exceptionHandler(const QScriptValue&)));
    }

    //設定指令碼支援的編碼【之前要設定】QTranslator::load()和 QCoreApplication::installTranslator()
    engine->installTranslatorFunctions();

    // iterate through module list and break if one module cannot be loaded
    QStringList modules;

//#if QT_VERSION >= 0x050000
//    modules << "qt.core" << "qt.gui" << "qt.printsupport" << "qt.widgets" << "qt.uitools" << "qt.webkit"
//            << "qt.webkitwidgets" << "qt.sql" << "qt.xml" << "qt.xmlpatterns";
//#else
//    modules << "qt.core" << "qt.gui" << "qt.uitools" << "qt.webkit" << "qt.sql"
//            << "qt.svg" << "qt.xml" << "qt.xmlpatterns" << "qt.network";
//#endif

    //引入擴充套件,將Qt中C++的模組在指令碼中建立對應的功能,例如gui,指令碼中就可以呼叫gui中對應的物件了
    modules = engine->availableExtensions();
    for (int i=0; i<modules.size(); i++) {
        engine->importExtension(modules.at(i));
        if (engine->hasUncaughtException()) {
            qWarning() << "ECMAScript extension module " << modules.at(i) << " could not be loaded:";
            qWarning() << engine->uncaughtException().toString();
            qWarning() << "Exception Backtrace:";
            qWarning() << engine->uncaughtExceptionBacktrace().join("\n");
            Q_ASSERT(false);
        }
    }
    
    //全域性指令碼物件
    QScriptValue globalObject = engine->globalObject();
    //建立一系列的全域性指令碼函式物件
    globalObject.setProperty("include", engine->newFunction(ecmaInclude, 1));
    globalObject.setProperty("evalAppEngine", engine->newFunction(ecmaEvalAppEngine));
    globalObject.setProperty("evalDocEngine", engine->newFunction(ecmaEvalDocEngine));
    globalObject.setProperty("print", engine->newFunction(ecmaPrint));
    globalObject.setProperty("qDebug", engine->newFunction(ecmaDebug));
    globalObject.setProperty("qWarning", engine->newFunction(ecmaWarning));
    globalObject.setProperty("qCritical", engine->newFunction(ecmaCritical));
    globalObject.setProperty("qGray", engine->newFunction(ecmaGray));

    globalObject.setProperty("bt", engine->newFunction(ecmaBacktrace));
    //globalObject.setProperty("attachDebugger", engine->newFunction(ecmaAttachDebugger));
    globalObject.setProperty("detachDebugger", engine->newFunction(ecmaDetachDebugger));
    globalObject.setProperty("collectGarbage", engine->newFunction(ecmaCollectGarbage));
    globalObject.setProperty("importExtension", engine->newFunction(ecmaImportExtension));
    globalObject.setProperty("isDeleted", engine->newFunction(ecmaIsDeleted));
    globalObject.setProperty("serialize", engine->newFunction(ecmaSerialize));
    globalObject.setProperty("addApplicationFont", engine->newFunction(ecmaAddApplicationFont));
    globalObject.setProperty("download", engine->newFunction(ecmaDownload));
    globalObject.setProperty("downloadToFile", engine->newFunction(ecmaDownloadToFile));
    globalObject.setProperty("mSleep", engine->newFunction(ecmaMSleep));
    globalObject.setProperty("parseXml", engine->newFunction(ecmaParseXml));

    //將應用程式物件繫結到指令碼物件
    globalObject.setProperty("qApp", engine->newQObject(dynamic_cast<RSingleApplication*>(qApp)));
    //globalObject.setProperty("getShapeIntersections", engine->newFunction(ecmaGetShapeIntersections));

    globalObject.setProperty("getAvailablePrinterNames", engine->newFunction(ecmaGetAvailablePrinterNames));
    globalObject.setProperty("getDefaultPrinterName", engine->newFunction(ecmaGetDefaultPrinterName));
    globalObject.setProperty("createPrinter", engine->newFunction(ecmaCreatePrinter));

    // fix Qt wrapper APIs
    //封裝QObject物件,並新增QObject物件的原型函式【engine->importExtension(modules.at(i));已經匯出QObject指令碼物件,下面是新增的QObject的擴充套件】
    QScriptValue classQObject = globalObject.property("QObject");
    classQObject.property("prototype").setProperty("findChild", engine->newFunction(ecmaQObjectFindChild));
    classQObject.property("prototype").setProperty("getChildren", engine->newFunction(ecmaQObjectGetChildren));
    classQObject.property("prototype").setProperty("getObjectId", engine->newFunction(ecmaGetObjectId));
    classQObject.property("prototype").setProperty("destroy", engine->newFunction(ecmaDestroy));

    //封裝QSortFilterProxyModel物件,並新增QSortFilterProxyModel物件的原型函式
    QScriptValue classQSortFilterProxyModel = globalObject.property("QSortFilterProxyModel");
    classQSortFilterProxyModel.property("prototype").setProperty("castToQAbstractItemModel",
            engine->newFunction(ecmaQSortFilterProxyModelCastToQAbstractItemModel));

    //封裝QDir物件,並新增QDir的分割屬性,如“/”或者“\\”
    QScriptValue classQDir = globalObject.property("QDir");
    classQDir.setProperty("separator", engine->newVariant(QDir::separator()));

    //封裝QEvent物件,並新增QEvent物件的原型函式
    QScriptValue classQEvent = globalObject.property("QEvent");
    classQEvent.property("prototype").setProperty("cast",
            engine->newFunction(ecmaQEventCast));

    QScriptValue classQDomNode = globalObject.property("QDomNode");
    classQDomNode.property("prototype").setProperty("appendChild",
            engine->newFunction(ecmaQDomNodeAppendChild));
    classQDomNode.property("prototype").setProperty("removeChild",
            engine->newFunction(ecmaQDomNodeRemoveChild));

    QScriptValue classQFontMetrics = globalObject.property("QFontMetrics");
    classQFontMetrics.property("prototype").setProperty("destroy",
            engine->newFunction(ecmaObjectDestroy<QFontMetrics>));

    QScriptValue classQPrinter = globalObject.property("QPrinter");
    classQPrinter.property("prototype").setProperty("destroy",
            engine->newFunction(ecmaObjectDestroy<QPrinter>));

    QScriptValue classQPrintDialog = globalObject.property("QPrintDialog");
    classQPrintDialog.property("prototype").setProperty("destroy",
            engine->newFunction(ecmaObjectDestroy<QPrintDialog>));

    QScriptValue classQTimer = globalObject.property("QTimer");
    classQTimer.property("prototype").setProperty("destroy",
            engine->newFunction(ecmaObjectDestroy<QTimer>));

    QScriptValue classQImageWriter = globalObject.property("QImageWriter");
    classQImageWriter.property("prototype").setProperty("destroy",
            engine->newFunction(ecmaObjectDestroy<QImageWriter>));

    QScriptValue classQPainter = globalObject.property("QPainter");
    classQPainter.property("prototype").setProperty("destroy",
            engine->newFunction(ecmaObjectDestroy<QPainter>));

    QScriptValue classQXmlResultItems = globalObject.property("QXmlResultItems");
    classQXmlResultItems.property("prototype").setProperty("destroy",
            engine->newFunction(ecmaObjectDestroy<QXmlResultItems>));

    QScriptValue classQXmlStreamWriter = globalObject.property("QXmlStreamWriter");
    classQXmlStreamWriter.property("prototype").setProperty("destroy",
            engine->newFunction(ecmaObjectDestroy<QXmlStreamWriter>));

    QScriptValue classQLayout = globalObject.property("QLayout");
    classQLayout.property("prototype").setProperty("getWidth",
            engine->newFunction(ecmaQLayoutGetWidth));

    QScriptValue classQByteArray = globalObject.property("QByteArray");
    classQByteArray.property("prototype").setProperty("toString",
            engine->newFunction(ecmaQByteArrayToString));

    QScriptValue classQUrl = globalObject.property("QUrl");
    classQUrl.property("prototype").setProperty("queryItems",
            engine->newFunction(ecmaQUrlQueryItems));

    QScriptValue classQLocale = globalObject.property("QLocale");
    classQLocale.property("prototype").setProperty("script",
            engine->newFunction(ecmaQLocaleScript));
    classQLocale.setProperty("scriptToString",
            engine->newFunction(ecmaQLocaleScriptToString));

#if QT_VERSION >= 0x050000
    QScriptValue classQLineEdit = globalObject.property("QLineEdit");
    classQLineEdit.property("prototype").setProperty("validator",
            engine->newFunction(ecmaQLineEditValidator));

//    QScriptValue classQWebPage = globalObject.property("QWebPage");
//    classQWebPage.property("prototype").setProperty("setLinkDelegationPolicy",
//            engine->newFunction(ecmaQWebPageSetLinkDelegationPolicy));

    QScriptValue classQFile = globalObject.property("QFile");
# if QT_VERSION < 0x050301
    classQFile.property("prototype").setProperty("close",
            engine->newFunction(ecmaQFileClose));
# endif
    classQFile.property("prototype").setProperty("readAll",
            engine->newFunction(ecmaQFileReadAll));

# if QT_VERSION < 0x050A00
    // causes crash in autosave under Qt 5.10:
    classQFile.property("prototype").setProperty("fileName",
            engine->newFunction(ecmaQFileFileName));
# endif
#endif

    QScriptValue classQt = globalObject.property("Qt");
    classQt.setProperty("escape",
            engine->newFunction(ecmaQtEscape));

    QScriptValue classQCoreApplication = globalObject.property(
            "QCoreApplication");
    classQCoreApplication.setProperty("arguments", engine->newFunction(
            ecmaArguments));
    classQCoreApplication.setProperty("exit", engine->newFunction(ecmaExit));

    // *** do not change the order ***
    //將下面的自定義類匯出為指令碼
    REcmaMath::initEcma(*engine);
    REcmaMatrix::initEcma(*engine);
    REcmaStemmer::initEcma(*engine);

    REcmaPropertyTypeId::initEcma(*engine);

    REcmaS::initEcma(*engine);
    REcmaUnit::initEcma(*engine);
    REcmaDebug::initEcma(*engine);
    REcmaSettings::initEcma(*engine);
    REcmaColor::initEcma(*engine);
    REcmaLineweight::initEcma(*engine);
    REcmaThread::initEcma(*engine);
    REcmaRunner::initEcma(*engine);
    REcmaLinetypePattern::initEcma(*engine);
    REcmaPattern::initEcma(*engine);
    REcmaPatternListMetric::initEcma(*engine);
    REcmaPatternListImperial::initEcma(*engine);
    REcmaFontList::initEcma(*engine);
    REcmaFileCache::initEcma(*engine);

    REcmaVector::initEcma(*engine);
    REcmaRefPoint::initEcma(*engine);

    REcmaImporter::initEcma(*engine);
    REcmaExporter::initEcma(*engine);

    REcmaShape::initEcma(*engine);
    REcmaSharedPointerShape::initEcma(*engine);
    REcmaArc::initEcma(*engine);
    REcmaSharedPointerArc::initEcma(*engine);
    REcmaBox::initEcma(*engine);
    REcmaCircle::initEcma(*engine);
    REcmaSharedPointerCircle::initEcma(*engine);
    REcmaEllipse::initEcma(*engine);
    REcmaSharedPointerEllipse::initEcma(*engine);
    REcmaLine::initEcma(*engine);
    REcmaSharedPointerLine::initEcma(*engine);
    REcmaXLine::initEcma(*engine);
    REcmaSharedPointerXLine::initEcma(*engine);
    REcmaRay::initEcma(*engine);
    REcmaSharedPointerRay::initEcma(*engine);
    REcmaPoint::initEcma(*engine);
    REcmaSharedPointerPoint::initEcma(*engine);
    REcmaPolyline::initEcma(*engine);
    REcmaSharedPointerPolyline::initEcma(*engine);
    REcmaSpline::initEcma(*engine);
    REcmaSharedPointerSpline::initEcma(*engine);
    REcmaTriangle::initEcma(*engine);
    REcmaSharedPointerTriangle::initEcma(*engine);
    REcmaTextLabel::initEcma(*engine);
    REcmaSharedPointerTextLabel::initEcma(*engine);

    REcmaStorage::initEcma(*engine);
    REcmaLinkedStorage::initEcma(*engine);
    REcmaMemoryStorage::initEcma(*engine);

    REcmaDocument::initEcma(*engine);
    REcmaDocumentInterface::initEcma(*engine);

    REcmaSelectionListener::initEcma(*engine);
    REcmaSelectionListenerAdapter::initEcma(*engine);
    REcmaExportListener::initEcma(*engine);
    REcmaExportListenerAdapter::initEcma(*engine);
    REcmaEntityExportListener::initEcma(*engine);
    REcmaEntityExportListenerAdapter::initEcma(*engine);
    REcmaImportListener::initEcma(*engine);
    REcmaImportListenerAdapter::initEcma(*engine);
    REcmaTransactionListener::initEcma(*engine);
    REcmaTransactionListenerAdapter::initEcma(*engine);
    REcmaInterTransactionListener::initEcma(*engine);
    REcmaInterTransactionListenerAdapter::initEcma(*engine);
    REcmaSnapListener::initEcma(*engine);
    REcmaNewDocumentListener::initEcma(*engine);
    REcmaNewDocumentListenerAdapter::initEcma(*engine);

    REcmaWidget::initEcma(*engine);
    REcmaGuiAction::initEcma(*engine);
    REcmaSpatialIndex::initEcma(*engine);
    REcmaSpatialIndexNavel::initEcma(*engine);
    REcmaSpatialIndexSimple::initEcma(*engine);
    REcmaSpatialIndexVisitor::initEcma(*engine);
    REcmaSpatialIndexVisitorAdapter::initEcma(*engine);

    REcmaGraphicsScene::initEcma(*engine);
    REcmaGraphicsSceneQt::initEcma(*engine);
    REcmaGraphicsSceneDrawable::initEcma(*engine);
    REcmaPainterPath::initEcma(*engine);
    REcmaPainterPathDevice::initEcma(*engine);

    REcmaGrid::initEcma(*engine);
    REcmaOrthoGrid::initEcma(*engine);
    REcmaRuler::initEcma(*engine);
    REcmaRulerQt::initEcma(*engine);

    REcmaSnap::initEcma(*engine);
    REcmaSnapEntityBase::initEcma(*engine);
    REcmaSnapAuto::initEcma(*engine);
    REcmaSnapCenter::initEcma(*engine);
    REcmaSnapDistance::initEcma(*engine);
    REcmaSnapEnd::initEcma(*engine);
    REcmaSnapFree::initEcma(*engine);
    REcmaSnapGrid::initEcma(*engine);
    REcmaSnapIntersection::initEcma(*engine);
    REcmaSnapMiddle::initEcma(*engine);
    REcmaSnapOnEntity::initEcma(*engine);
    REcmaSnapPerpendicular::initEcma(*engine);
    REcmaSnapReference::initEcma(*engine);
    REcmaSnapTangential::initEcma(*engine);

    REcmaSnapRestriction::initEcma(*engine);
    REcmaRestrictAngleLength::initEcma(*engine);
    REcmaRestrictHorizontal::initEcma(*engine);
    REcmaRestrictVertical::initEcma(*engine);
    REcmaRestrictOrthogonal::initEcma(*engine);
    REcmaRestrictOff::initEcma(*engine);

    REcmaGraphicsView::initEcma(*engine);
    REcmaGraphicsViewImage::initEcma(*engine);
    REcmaGraphicsViewQt::initEcma(*engine);

    REcmaMainWindow::initEcma(*engine);
    REcmaMainWindowQt::initEcma(*engine);
    REcmaMdiArea::initEcma(*engine);
    REcmaMdiChildQt::initEcma(*engine);

    REcmaAction::initEcma(*engine);
    REcmaActionAdapter::initEcma(*engine);
    REcmaNavigationAction::initEcma(*engine);
    REcmaScriptAction::initEcma(*engine);

    REcmaScriptHandler::initEcma(*engine);

    REcmaEventFilter::initEcma(*engine);
    REcmaEventHandler::initEcma(*engine);

    REcmaTerminateEvent::initEcma(*engine);
    REcmaInputEvent::initEcma(*engine);
    REcmaMouseEvent::initEcma(*engine);
    REcmaWheelEvent::initEcma(*engine);
    REcmaTabletEvent::initEcma(*engine);
    REcmaCloseCurrentEvent::initEcma(*engine);

    REcmaCommandEvent::initEcma(*engine);
    REcmaCoordinateEvent::initEcma(*engine);
    REcmaEntityPickEvent::initEcma(*engine);
    REcmaCoordinateListener::initEcma(*engine);
    REcmaCoordinateListenerAdapter::initEcma(*engine);

    REcmaObject::initEcma(*engine);
    REcmaSharedPointerObject::initEcma(*engine);
    REcmaDocumentVariables::initEcma(*engine);
    REcmaSharedPointerDocumentVariables::initEcma(*engine);
    REcmaEntity::initEcma(*engine);
    REcmaSharedPointerEntity::initEcma(*engine);
    REcmaLayer::initEcma(*engine);
    REcmaSharedPointerLayer::initEcma(*engine);
    REcmaLayout::initEcma(*engine);
    REcmaSharedPointerLayout::initEcma(*engine);
    REcmaBlock::initEcma(*engine);
    REcmaSharedPointerBlock::initEcma(*engine);
    REcmaView::initEcma(*engine);
    REcmaSharedPointerView::initEcma(*engine);
    REcmaLinetype::initEcma(*engine);
    REcmaSharedPointerLinetype::initEcma(*engine);
    REcmaUcs::initEcma(*engine);
    REcmaSharedPointerUcs::initEcma(*engine);

    REcmaEntityData::initEcma(*engine);

    REcmaBlockReferenceData::initEcma(*engine);
    REcmaBlockReferenceEntity::initEcma(*engine);
    REcmaSharedPointerBlockReferenceEntity::initEcma(*engine);

    REcmaPointData::initEcma(*engine);
    REcmaPointEntity::initEcma(*engine);
    REcmaSharedPointerPointEntity::initEcma(*engine);

    REcmaLineData::initEcma(*engine);
    REcmaLineEntity::initEcma(*engine);
    REcmaSharedPointerLineEntity::initEcma(*engine);

    REcmaXLineData::initEcma(*engine);
    REcmaXLineEntity::initEcma(*engine);
    REcmaSharedPointerXLineEntity::initEcma(*engine);

    REcmaRayData::initEcma(*engine);
    REcmaRayEntity::initEcma(*engine);
    REcmaSharedPointerRayEntity::initEcma(*engine);

    REcmaCircleData::initEcma(*engine);
    REcmaCircleEntity::initEcma(*engine);
    REcmaSharedPointerCircleEntity::initEcma(*engine);

    REcmaArcData::initEcma(*engine);
    REcmaArcEntity::initEcma(*engine);
    REcmaSharedPointerArcEntity::initEcma(*engine);

    REcmaEllipseData::initEcma(*engine);
    REcmaEllipseEntity::initEcma(*engine);
    REcmaSharedPointerEllipseEntity::initEcma(*engine);

    REcmaPolylineData::initEcma(*engine);
    REcmaPolylineEntity::initEcma(*engine);
    REcmaSharedPointerPolylineEntity::initEcma(*engine);

    REcmaSolidData::initEcma(*engine);
    REcmaSolidEntity::initEcma(*engine);
    REcmaSharedPointerSolidEntity::initEcma(*engine);

    REcmaTraceData::initEcma(*engine);
    REcmaTraceEntity::initEcma(*engine);
    REcmaSharedPointerTraceEntity::initEcma(*engine);

    REcmaFaceData::initEcma(*engine);
    REcmaFaceEntity::initEcma(*engine);
    REcmaSharedPointerFaceEntity::initEcma(*engine);

    REcmaViewportData::initEcma(*engine);
    REcmaViewportEntity::initEcma(*engine);
    REcmaSharedPointerViewportEntity::initEcma(*engine);

    REcmaSplineData::initEcma(*engine);
    REcmaSplineEntity::initEcma(*engine);
    REcmaSharedPointerSplineEntity::initEcma(*engine);

    REcmaTextBasedData::initEcma(*engine);
    REcmaTextBasedEntity::initEcma(*engine);
    REcmaSharedPointerTextBasedData::initEcma(*engine);
    REcmaSharedPointerTextBasedEntity::initEcma(*engine);

    REcmaTextData::initEcma(*engine);
    REcmaTextEntity::initEcma(*engine);
    REcmaSharedPointerTextData::initEcma(*engine);
    REcmaSharedPointerTextEntity::initEcma(*engine);

    REcmaAttributeDefinitionData::initEcma(*engine);
    REcmaAttributeDefinitionEntity::initEcma(*engine);
    REcmaSharedPointerAttributeDefinitionEntity::initEcma(*engine);

    REcmaAttributeData::initEcma(*engine);
    REcmaAttributeEntity::initEcma(*engine);
    REcmaSharedPointerAttributeEntity::initEcma(*engine);

    REcmaLeaderData::initEcma(*engine);
    REcmaLeaderEntity::initEcma(*engine);
    REcmaSharedPointerLeaderEntity::initEcma(*engine);

    REcmaHatchData::initEcma(*engine);
    REcmaHatchEntity::initEcma(*engine);
    REcmaSharedPointerHatchEntity::initEcma(*engine);

    REcmaImageData::initEcma(*engine);
    REcmaImageEntity::initEcma(*engine);
    REcmaSharedPointerImageEntity::initEcma(*engine);

    REcmaDimensionData::initEcma(*engine);
    REcmaDimensionEntity::initEcma(*engine);
    REcmaSharedPointerDimensionEntity::initEcma(*engine);

    REcmaDimLinearData::initEcma(*engine);
    REcmaDimLinearEntity::initEcma(*engine);
    REcmaSharedPointerDimLinearEntity::initEcma(*engine);

    REcmaDimAlignedData::initEcma(*engine);
    REcmaDimAlignedEntity::initEcma(*engine);
    REcmaSharedPointerDimAlignedEntity::initEcma(*engine);

    REcmaDimAngularData::initEcma(*engine);
    REcmaDimAngularEntity::initEcma(*engine);
    REcmaSharedPointerDimAngularEntity::initEcma(*engine);

    REcmaDimAngular2LData::initEcma(*engine);
    REcmaDimAngular2LEntity::initEcma(*engine);
    REcmaSharedPointerDimAngular2LEntity::initEcma(*engine);

    REcmaDimAngular3PData::initEcma(*engine);
    REcmaDimAngular3PEntity::initEcma(*engine);
    REcmaSharedPointerDimAngular3PEntity::initEcma(*engine);

    REcmaDimArcLengthData::initEcma(*engine);
    REcmaDimArcLengthEntity::initEcma(*engine);
    REcmaSharedPointerDimArcLengthEntity::initEcma(*engine);

    REcmaDimDiametricData::initEcma(*engine);
    REcmaDimDiametricEntity::initEcma(*engine);
    REcmaSharedPointerDimDiametricEntity::initEcma(*engine);

    REcmaDimRadialData::initEcma(*engine);
    REcmaDimRadialEntity::initEcma(*engine);
    REcmaSharedPointerDimRadialEntity::initEcma(*engine);

    REcmaDimRotatedData::initEcma(*engine);
    REcmaDimRotatedEntity::initEcma(*engine);
    REcmaSharedPointerDimRotatedEntity::initEcma(*engine);

    REcmaDimOrdinateData::initEcma(*engine);
    REcmaDimOrdinateEntity::initEcma(*engine);
    REcmaSharedPointerDimOrdinateEntity::initEcma(*engine);

    REcmaTransaction::initEcma(*engine);

    REcmaFileImporter::initEcma(*engine);
    REcmaFileImporterAdapter::initEcma(*engine);
    REcmaFileImporterFactory::initEcma(*engine);
    REcmaFileImporterFactoryAdapter::initEcma(*engine);
    REcmaFileImporterRegistry::initEcma(*engine);

    REcmaFileExporter::initEcma(*engine);
    REcmaFileExporterAdapter::initEcma(*engine);
    REcmaFileExporterFactory::initEcma(*engine);
    REcmaFileExporterFactoryAdapter::initEcma(*engine);
    REcmaFileExporterRegistry::initEcma(*engine);

    REcmaOperation::initEcma(*engine);

    REcmaAddObjectsOperation::initEcma(*engine);
    REcmaClipboardOperation::initEcma(*engine);
    REcmaDeleteObjectsOperation::initEcma(*engine);

    REcmaAddObjectOperation::initEcma(*engine);
    REcmaChangePropertyOperation::initEcma(*engine);
    REcmaCopyOperation::initEcma(*engine);
    REcmaDeleteAllEntitiesOperation::initEcma(*engine);
    REcmaDeleteObjectOperation::initEcma(*engine);
    REcmaDeleteSelectionOperation::initEcma(*engine);
    REcmaMixedOperation::initEcma(*engine);
    REcmaModifyObjectOperation::initEcma(*engine);
    REcmaModifyObjectsOperation::initEcma(*engine);
    REcmaMoveReferencePointOperation::initEcma(*engine);
    REcmaMoveSelectionOperation::initEcma(*engine);
    REcmaScaleSelectionOperation::initEcma(*engine);
    REcmaPasteOperation::initEcma(*engine);
    REcmaClickReferencePointOperation::initEcma(*engine);
    REcmaOperationUtils::initEcma(*engine);

    REcmaTransformation::initEcma(*engine);

    REcmaTranslation::initEcma(*engine);

    REcmaCommandLine::initEcma(*engine);
    REcmaTextEdit::initEcma(*engine);
    REcmaMathLineEdit::initEcma(*engine);
    REcmaCharacterWidget::initEcma(*engine);
    REcmaDockWidget::initEcma(*engine);
    REcmaToolButton::initEcma(*engine);

    REcmaPropertyListener::initEcma(*engine);
    REcmaPropertyEditor::initEcma(*engine);

    REcmaToolMatrixItemDelegate::initEcma(*engine);
    REcmaFlowLayout::initEcma(*engine);
    REcmaListWidget::initEcma(*engine);
    REcmaTreeWidget::initEcma(*engine);
    REcmaListView::initEcma(*engine);
    REcmaLayerListener::initEcma(*engine);
    REcmaLayerListenerAdapter::initEcma(*engine);
    REcmaBlockListener::initEcma(*engine);
    REcmaBlockListenerAdapter::initEcma(*engine);
    REcmaViewListener::initEcma(*engine);
    REcmaViewListenerAdapter::initEcma(*engine);
    REcmaPenListener::initEcma(*engine);
    REcmaPenListenerAdapter::initEcma(*engine);
    REcmaColorCombo::initEcma(*engine);
    REcmaLineweightCombo::initEcma(*engine);
    REcmaLinetypeCombo::initEcma(*engine);
    REcmaFontChooserWidget::initEcma(*engine);
    REcmaFontDatabase::initEcma(*engine);

    REcmaPluginLoader::initEcma(*engine);
    REcmaPluginInfo::initEcma(*engine);
    REcmaPluginInterface::initEcma(*engine);

    REcmaFontList::initEcma(*engine);

    REcmaPropertyEvent::initEcma(*engine);

    REcmaPropertyChange::initEcma(*engine);
    REcmaPropertyAttributes::initEcma(*engine);

    REcmaFileSystemModel::initEcma(*engine);

    REcmaTextLayout::initEcma(*engine);

//#if QT_VERSION < 0x050600
//#  if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
//    REcmaWebView::initEcma(*engine);
//#  endif
//#endif

    REcmaKeyListener::initEcma(*engine);
    REcmaKeyListenerAdapter::initEcma(*engine);

    REcmaFocusListener::initEcma(*engine);
    REcmaFocusListenerAdapter::initEcma(*engine);
    REcmaViewFocusListener::initEcma(*engine);
    REcmaViewFocusListenerAdapter::initEcma(*engine);

    REcmaPreferencesListener::initEcma(*engine);
    REcmaPreferencesListenerAdapter::initEcma(*engine);

    REcmaTextRenderer::initEcma(*engine);

    REcmaDxfServices::initEcma(*engine);

    REcmaAutoLoadEcma::initEcma(*engine);

    REcmaZip::initEcma(*engine);


    // *** end of "do not change the order" ***

    // give plugins a chance to initialize their script extensions:
    //將指令碼中的類匯出為指令碼對應的類
    RPluginLoader::initScriptExtensions(*engine);

    // eval auto load scripts:
    //載入指令碼列表,並執行指令碼
    QStringList files = RAutoLoadEcma::getAutoLoadFiles();
    for (int i=0; i<files.size(); i++) {
        doScript(files[i]);
    }
}