-#include "PartSet_Module.h"
+#include <PartSet_Module.h>
+#include <PartSet_OperationSketch.h>
+#include <ModuleBase_Operation.h>
+
+#include <XGUI_MainWindow.h>
+#include <XGUI_Displayer.h>
+#include <XGUI_Viewer.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_OperationMgr.h>
+
+#include <Config_PointerMessage.h>
#include <Config_ModuleReader.h>
-#include <Config_FeatureReader.h>
+#include <Config_WidgetReader.h>
+#include <Events_Loop.h>
+#include <Events_Message.h>
-#include <Event_Loop.hxx>
+#include <QObject>
+#include <QString>
+
+#ifdef _DEBUG
+#include <QDebug>
+#endif
-#include <QFile>
-#include <QDir>
-#include <QApplication>
-#include <QTextStream>
/*!Create and return new instance of XGUI_Module*/
extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
return new PartSet_Module(theWshop);
}
-
PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
{
- myWorkshop = theWshop;
-}
+ myWorkshop = theWshop;
+ XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
+ connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
+ connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
+ this, SLOT(onOperationStopped(ModuleBase_Operation*)));
+}
PartSet_Module::~PartSet_Module()
{
void PartSet_Module::createFeatures()
{
- Config_ModuleReader* aXMLReader = new Config_ModuleReader();
- aXMLReader->setAutoImport(true);
- aXMLReader->readAll();
- delete aXMLReader;
+ Config_ModuleReader aXMLReader = Config_ModuleReader();
+ aXMLReader.setAutoImport(true);
+ aXMLReader.readAll();
}
void PartSet_Module::featureCreated(XGUI_Command* theFeature)
{
- QString aFtId = theFeature->getId();
- if(aFtId == "new_point") {
- theFeature->connectTo(this, SLOT(onCommandTriggered()));
- }
+ theFeature->connectTo(this, SLOT(onFeatureTriggered()));
}
-void PartSet_Module::onCommandTriggered()
+std::string PartSet_Module::modulePlugin()
{
Config_ModuleReader aModuleReader = Config_ModuleReader();
aModuleReader.readAll();
- std::string aPluginName = aModuleReader.pluginsList().front();
- Config_FeatureReader* aReader = new Config_FeatureReader(aPluginName);
+ std::map < std::string, std::string > aPluginMap = aModuleReader.plugins();
+ std::string aPluginName = aPluginMap["PartSetPlugin"];
+ return aPluginName;
+}
+
+/*
+ *
+ */
+void PartSet_Module::onFeatureTriggered()
+{
+ std::string aPluginName = modulePlugin();
+ Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginName);
+ aWdgReader.readAll();
XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
- std::string aXMLWidgetCfg =
- aReader->featureWidgetCfg(aCmd->getId().toStdString());
- delete aReader;
+ QString aCmdId = aCmd->id();
+ std::string aXmlCfg = aWdgReader.featureWidgetCfg(aCmdId.toStdString());
+ std::string aDescription = aWdgReader.featureDescription(aCmdId.toStdString());
+ ModuleBase_PropPanelOperation* aPartSetOp;
+ if (aCmdId == "Sketch" ) {
+ aPartSetOp = new PartSet_OperationSketch(aCmdId, this);
+ } else {
+ aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this);
+ }
+ aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
+ aPartSetOp->setDescription(QString::fromStdString(aDescription));
+
+ //TODO(sbh): Implement static method to extract event id [SEID]
+ static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
+ Config_PointerMessage aMessage(aModuleEvent, this);
+ aMessage.setPointer(aPartSetOp);
+ Events_Loop::loop()->send(aMessage);
+}
+
+void PartSet_Module::onOperationStarted()
+{
+ ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+
+ PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+ if (aPreviewOp) {
+ connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
+ aPreviewOp, SLOT(onViewSelectionChanged()));
+ visualizePreview(true);
+ }
+}
+
+void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
+{
+ ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
+ if (!anOperation)
+ return;
+
+ PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+ if (aPreviewOp) {
+ disconnect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
+ aPreviewOp, SLOT(onViewSelectionChanged()));
+ visualizePreview(false);
+ }
+}
+
+void PartSet_Module::visualizePreview(bool isDisplay)
+{
+ ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+ if (!anOperation)
+ return;
+
+ PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+ if (!aPreviewOp)
+ return;
+
+ if (isDisplay) {
+ myWorkshop->displayer()->LocalSelection(anOperation->feature(), aPreviewOp->preview(),
+ aPreviewOp->getSelectionMode());
+ }
+ else {
+ myWorkshop->displayer()->GlobalSelection(false);
+ myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview());
+ }
}