Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index 63f7a1a373a1aa1ada079af3a030afb43eb502fc..79edcc6a1c598e0d8786581ad2c9de181f87a037 100644 (file)
@@ -2,11 +2,15 @@
 #include <PartSet_OperationSketch.h>
 #include <PartSet_OperationSketchLine.h>
 #include <PartSet_OperationEditLine.h>
+#include <PartSet_OperationConstraint.h>
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
 #include <PartSet_Listener.h>
+#include <PartSet_TestOCC.h>
+#include <PartSet_Presentation.h>
 
 #include <ModuleBase_Operation.h>
+#include <ModelAPI_Object.h>
 
 #include <XGUI_MainWindow.h>
 #include <XGUI_Displayer.h>
@@ -17,6 +21,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>
@@ -28,6 +35,7 @@
 #include <GeomAPI_Shape.h>
 
 #include <AIS_ListOfInteractive.hxx>
+#include <AIS_DimensionSelectionMode.hxx>
 
 #include <QObject>
 #include <QMouseEvent>
@@ -37,7 +45,6 @@
 #include <QDebug>
 #endif
 
-
 /*!Create and return new instance of XGUI_Module*/
 extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
 {
@@ -51,9 +58,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 +114,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 +132,26 @@ 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&)));
   }
 }
 
@@ -179,6 +212,13 @@ void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
 {
   myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
   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)
@@ -193,8 +233,8 @@ void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr<Mo
     std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted(TopAbs_VERTEX);
     aPreviewOp->init(theFeature, aSelected, aHighlighted);
   }
-  myWorkshop->actionsMgr()->updateCheckState();
   sendOperation(anOperation);
+  myWorkshop->actionsMgr()->updateCheckState();
 }
 
 void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
@@ -277,12 +317,11 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
   std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
 
   // create the operation
-  ModuleBase_Operation* anOperation;
+  ModuleBase_Operation* anOperation = 0;
   if (theCmdId == PartSet_OperationSketch::Type()) {
     anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
   }
-  else if(theCmdId == PartSet_OperationSketchLine::Type() ||
-          theCmdId == PartSet_OperationEditLine::Type()) {
+  else {
     ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
     boost::shared_ptr<ModelAPI_Feature> aSketch;
     PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
@@ -290,10 +329,13 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
       aSketch = aPrevOp->sketch();
     if (theCmdId == PartSet_OperationSketchLine::Type())
       anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch);
-    else
+    else if (theCmdId == PartSet_OperationEditLine::Type())
       anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch);
+    else if (theCmdId == PartSet_OperationConstraint::Type())
+      anOperation = new PartSet_OperationConstraint(theCmdId.c_str(), this, aSketch);
   }
-  else {
+
+  if (!anOperation) {
     anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
   }
   anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
@@ -323,6 +365,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()));
     }
   }
 
@@ -352,8 +396,16 @@ void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFea
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   if (isDisplay) {
     boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
-    aDisplayer->Redisplay(theFeature,
-                          aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+    Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+                           theFeature, aPreviewOp->sketch(),
+                           aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
+                           aDisplayer->GetAISObject(theFeature));
+
+    int aSelectionMode = -1;
+    if (theFeature->getKind() == "SketchConstraintLength") {
+      aSelectionMode = AIS_DSM_Text;
+    }
+    aDisplayer->Redisplay(theFeature, anAIS, aSelectionMode, false);
   }
   else
     aDisplayer->Erase(theFeature, false);
@@ -398,8 +450,12 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
   for (; anIt != aLast; anIt++) {
     boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
     boost::shared_ptr<GeomAPI_Shape> aPreview = (*anIt).second;
-    aDisplayer->Redisplay(aFeature,
-                          aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+    Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+                           aFeature, aPreviewOp->sketch(),
+                           aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
+                           aDisplayer->GetAISObject(aFeature));
+    if (!anAIS.IsNull())
+      aDisplayer->Redisplay(aFeature, anAIS, -1, false);
     aDisplayer->ActivateInLocalContext(aFeature, aModes, false);
   }
   aDisplayer->UpdateViewer();
@@ -407,11 +463,19 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
 
 void PartSet_Module::editFeature(FeaturePtr theFeature)
 {
-  /*if (!theFeature)
+  if (!theFeature)
     return;
 
   if (theFeature->getKind() == "Sketch") {
-    onLaunchOperation(theFeature->getKind(), theFeature);
-    visualizePreview(theFeature, true);
-  }*/
+    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());
+    }
+  }
 }