Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index 606c5789966eee02a806b0a68e020ab71126e0ed..99cab29e5c2a2be1f1c3660db3f475f92ec16c61 100644 (file)
@@ -5,8 +5,10 @@
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
 #include <PartSet_Listener.h>
+#include <PartSet_TestOCC.h>
 
 #include <ModuleBase_Operation.h>
+#include <ModelAPI_Object.h>
 
 #include <XGUI_MainWindow.h>
 #include <XGUI_Displayer.h>
@@ -17,6 +19,9 @@
 #include <XGUI_ViewPort.h>
 #include <XGUI_ActionsMgr.h>
 #include <XGUI_ViewerProxy.h>
+#include <XGUI_ContextMenuMgr.h>
+#include <XGUI_PropertyPanel.h>
+#include <XGUI_Tools.h>
 
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
@@ -37,7 +42,6 @@
 #include <QDebug>
 #endif
 
-
 /*!Create and return new instance of XGUI_Module*/
 extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
 {
@@ -51,9 +55,16 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
 
   XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
 
+  connect(anOperationMgr, SIGNAL(operationStarted()),
+          this, SLOT(onOperationStarted()));
+
   connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
           this, SLOT(onOperationStopped(ModuleBase_Operation*)));
 
+  XGUI_ContextMenuMgr* aContextMenuMgr = myWorkshop->contextMenuMgr();
+  connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), 
+          this, SLOT(onContextMenuCommand(const QString&, bool)));
+
   connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)),
           this, SLOT(onMousePressed(QMouseEvent*)));
   connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)),
@@ -100,6 +111,11 @@ std::string PartSet_Module::featureFile(const std::string& theFeatureId)
  */
 void PartSet_Module::onFeatureTriggered()
 {
+  //PartSet_TestOCC::local_selection_change_shape(myWorkshop->viewer()->AISContext(),
+  //                                   myWorkshop->viewer()->activeView());
+
+  //PartSet_TestOCC::local_selection_erase(myWorkshop->viewer()->AISContext(),
+  //                                       myWorkshop->viewer()->activeView());
   QAction* aCmd = dynamic_cast<QAction*>(sender());
   //Do nothing on uncheck
   if(aCmd->isCheckable() && !aCmd->isChecked())
@@ -113,12 +129,34 @@ void PartSet_Module::launchOperation(const QString& theCmdId)
   sendOperation(anOperation);
 }
 
+void PartSet_Module::onOperationStarted()
+{
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
+                                       myWorkshop->operationMgr()->currentOperation());
+  if (aPreviewOp) {
+    XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
+    connect(aPreviewOp, SIGNAL(focusActivated(const std::string&)),
+            aPropPanel, SLOT(onFocusActivated(const std::string&)));
+  }
+}
+
 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
 {
   if (!theOperation)
     return;
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
   if (aPreviewOp) {
+    XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
+    disconnect(aPreviewOp, SIGNAL(focusActivated(const std::string&)),
+               aPropPanel, SLOT(onFocusActivated(const std::string&)));
+  }
+}
+
+void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
+{
+  QFeatureList aFeatures = myWorkshop->selector()->selectedFeatures();
+  if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
+    editFeature(aFeatures.first());
   }
 }
 
@@ -170,7 +208,14 @@ void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
 {
   myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
-  myWorkshop->actionsMgr()->setNestedActionsEnabled(true);
+  myWorkshop->actionsMgr()->update();
+
+  //PartSet_TestOCC::testSelection(myWorkshop);
+}
+
+void PartSet_Module::onFitAllView()
+{
+  myWorkshop->viewer()->fitAll();
 }
 
 void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr<ModelAPI_Feature> theFeature)
@@ -180,12 +225,13 @@ void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr<Mo
   if (aPreviewOp)
   {
     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-    std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected();
-    std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted();
+      // refill the features list with avoiding of the features, obtained only by vertex shape (TODO)
+    std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected(TopAbs_VERTEX);
+    std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted(TopAbs_VERTEX);
     aPreviewOp->init(theFeature, aSelected, aHighlighted);
   }
-  myWorkshop->actionsMgr()->setActionChecked(anOperation->getDescription()->operationId(), true);
   sendOperation(anOperation);
+  myWorkshop->actionsMgr()->updateCheckState();
 }
 
 void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
@@ -314,6 +360,8 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
     if (aSketchOp) {
       connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
               this, SLOT(onPlaneSelected(double, double, double)));
+      connect(aSketchOp, SIGNAL(fitAllView()),
+              this, SLOT(onFitAllView()));
     }
   }
 
@@ -396,3 +444,21 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
   aDisplayer->UpdateViewer();
 }
 
+void PartSet_Module::editFeature(FeaturePtr theFeature)
+{
+  if (!theFeature)
+    return;
+
+  if (theFeature->getKind() == "Sketch") {
+    FeaturePtr aFeature = theFeature;
+    if (XGUI_Tools::isModelObject(aFeature)) {
+      ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
+      aFeature = aObject->featureRef();
+    }
+
+    if (aFeature) {
+      onLaunchOperation(aFeature->getKind(), aFeature);
+      updateCurrentPreview(aFeature->getKind());
+    }
+  }
+}