Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index bbdde0c198ea928a24a19b0d40d01551e41c28d3..1a0e84dd5c0125236e3df181065eb3af7b6bc42f 100644 (file)
@@ -5,12 +5,17 @@
 
 #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_WidgetReader.h>
-#include <Event_Loop.h>
-#include <Event_Message.h>
+#include <Events_Loop.h>
+#include <Events_Message.h>
+
+#include <AIS_ListOfInteractive.hxx>
 
 #include <QObject>
 #include <QString>
@@ -29,6 +34,14 @@ extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
 PartSet_Module::PartSet_Module(XGUI_Workshop* 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*)));
+  if (!myWorkshop->isSalomeMode())
+    connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
+            this, SLOT(onViewSelectionChanged()));
 }
 
 PartSet_Module::~PartSet_Module()
@@ -58,36 +71,80 @@ std::string PartSet_Module::featureFile(const std::string& theFeatureId)
 void PartSet_Module::onFeatureTriggered()
 {
   XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
-  QString aCmdId = aCmd->id();
-  std::string aStdCmdId = aCmdId.toStdString();
+  launchOperation(aCmd->id());
+}
+  
+void PartSet_Module::launchOperation(const QString& theCmdId)
+{
+  std::string aStdCmdId = theCmdId.toStdString();
   std::string aPluginFileName = featureFile(aStdCmdId);
   Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
   aWdgReader.readAll();
   std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
   std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
   ModuleBase_PropPanelOperation* aPartSetOp;
-  if (aCmdId == "Sketch" ) {
-    aPartSetOp = new PartSet_OperationSketch(aCmdId, this);
+  if (theCmdId == "Sketch" ) {
+    aPartSetOp = new PartSet_OperationSketch(theCmdId, this);
   } else {
-    aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this);
-  }
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(aPartSetOp);
-  if (aPreviewOp) {
-    connect(aPreviewOp, SIGNAL(visualizePreview()), this, SLOT(onVisualizePreview()));
+    aPartSetOp = new ModuleBase_PropPanelOperation(theCmdId, this);
   }
   aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
   aPartSetOp->setDescription(QString::fromStdString(aDescription));
 
   //TODO(sbh): Implement static method to extract event id [SEID]
-  static Event_ID aModuleEvent = Event_Loop::eventByName("PartSetModuleEvent");
+  static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
   Config_PointerMessage aMessage(aModuleEvent, this);
   aMessage.setPointer(aPartSetOp);
-  Event_Loop::loop()->send(aMessage);
+  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) {
+    visualizePreview(true);
+    connect(aPreviewOp, SIGNAL(viewerProjectionChange(double, double, double)),
+            this, SLOT(onViewerProjectionChange(double, double, double)));
+  }
+}
+
+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)
+    visualizePreview(false);
 }
 
-void PartSet_Module::onVisualizePreview()
+void PartSet_Module::onViewSelectionChanged()
 {
-  ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+  if (aPreviewOp) {
+    XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+    if (aViewer) {
+      NCollection_List<TopoDS_Shape> aList;
+      aViewer->getSelectedShapes(aList);
+      aPreviewOp->setSelectedShapes(aList);
+    }
+  }
+}
+
+void PartSet_Module::onViewerProjectionChange(double theX, double theY, double theZ)
+{
+  XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+  if (aViewer) {
+    aViewer->setViewProjection(theX, theY, theZ);
+  }
+}
+
+void PartSet_Module::visualizePreview(bool isDisplay)
+{
+  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
   if (!anOperation)
     return;
 
@@ -95,5 +152,12 @@ void PartSet_Module::onVisualizePreview()
   if (!aPreviewOp)
     return;
 
-  myWorkshop->displayer()->Display(anOperation->feature(), aPreviewOp->preview());
+  if (isDisplay) {
+    myWorkshop->displayer()->LocalSelection(anOperation->feature(), aPreviewOp->preview(),
+                                            aPreviewOp->getSelectionMode());
+  }
+  else {
+    myWorkshop->displayer()->GlobalSelection(false);
+    myWorkshop->displayer()->Erase(anOperation->feature());
+  }
 }