Salome HOME
Issue #2309 Possibility to hide faces : transparency using
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index a9845e2a57c3f542750a8a1681dd008eaf3fea68..1455f1ab08e55363ff68b2c20a1d1b38ac2e320f 100755 (executable)
@@ -37,7 +37,6 @@
 #include "PartSet_MenuMgr.h"
 #include "PartSet_CustomPrs.h"
 #include "PartSet_IconFactory.h"
-#include "PartSet_WidgetChoice.h"
 #include "PartSet_OverconstraintListener.h"
 
 #include "PartSet_Filters.h"
@@ -52,6 +51,7 @@
 #include <ModuleBase_IViewer.h>
 #include <ModuleBase_IViewWindow.h>
 #include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_WidgetChoice.h>
 #include <ModuleBase_WidgetEditor.h>
 #include <ModuleBase_WidgetValidated.h>
 #include <ModuleBase_Tools.h>
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Dir.h>
 
-#include <XGUI_Displayer.h>
-#include <XGUI_Workshop.h>
-#include <XGUI_OperationMgr.h>
-#include <XGUI_PropertyPanel.h>
-#include <XGUI_ModuleConnector.h>
+#include <XGUI_ActiveControlMgr.h>
+#include <XGUI_ActiveControlSelector.h>
+#include <XGUI_ActionsMgr.h>
 #include <XGUI_ContextMenuMgr.h>
-#include <XGUI_Tools.h>
-#include <XGUI_ObjectsBrowser.h>
-#include <XGUI_SelectionMgr.h>
+#include <XGUI_CustomPrs.h>
 #include <XGUI_DataModel.h>
+#include <XGUI_Displayer.h>
 #include <XGUI_ErrorMgr.h>
-#include <XGUI_CustomPrs.h>
+#include <XGUI_FacesPanelSelector.h>
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_ObjectsBrowser.h>
+#include <XGUI_OperationMgr.h>
+#include <XGUI_PropertyPanel.h>
 #include <XGUI_SelectionMgr.h>
-#include <XGUI_ActionsMgr.h>
+#include <XGUI_Tools.h>
+#include <XGUI_Workshop.h>
 
-#include <SketchPlugin_Feature.h>
-#include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_ConstraintAngle.h>
 #include <SketchPlugin_ConstraintLength.h>
 #include <SketchPlugin_ConstraintDistance.h>
 #include <SketchPlugin_ConstraintParallel.h>
 #include <SketchPlugin_ConstraintPerpendicular.h>
 #include <SketchPlugin_ConstraintRadius.h>
+#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Projection.h>
+#include <SketchPlugin_Sketch.h>
 
 #include <SketcherPrs_SymbolPrs.h>
 #include <SketcherPrs_Coincident.h>
@@ -185,6 +188,14 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
                           "Color of removed feature in operation", Config_Prop::Color,
                           PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
+  Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
+                          "Color of sketch plane", Config_Prop::Color,
+                          PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
+
+  Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
+                                   "Hidden faces transparency",
+                                   Config_Prop::Double,
+                                   "0.8");
 }
 
 PartSet_Module::~PartSet_Module()
@@ -219,6 +230,17 @@ void PartSet_Module::deactivateSelectionFilters()
   }
 }
 
+void PartSet_Module::updateActiveSelectionFilters()
+{
+  XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
+  XGUI_ActiveControlSelector* anActiveSelector = aWorkshop->activeControlMgr()->activeSelector();
+
+  if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
+    sketchMgr()->deactivateSelectionFilters();
+  else
+    sketchMgr()->activateSelectionFilters();
+}
+
 void PartSet_Module::storeSelection()
 {
   // cash is used only to restore selection, so it should be filled in storeSelection and
@@ -255,6 +277,7 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
   aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
+  aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
   aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
   aFactory->registerValidator("PartSet_MultyTranslationSelection",
     new PartSet_MultyTranslationSelection);
@@ -620,7 +643,6 @@ bool PartSet_Module::isSketchNeutralPointActivated() const
 void PartSet_Module::closeDocument()
 {
   myActivePartIndex = QModelIndex();
-  clearViewer();
 }
 
 void PartSet_Module::clearViewer()
@@ -788,7 +810,7 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
   } else if (theType == "sketch_launcher") {
     aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
   } else if (theType == "module_choice") {
-    aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi);
+    aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
     connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
             this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
   }
@@ -931,15 +953,21 @@ void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
 {
   Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
   if (!anAIS.IsNull()) {
+    bool aToUseZLayer = false;
+    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+    if (aFeature.get() && PartSet_Tools::findRefsToMeFeature(aFeature,
+                                                        SketchPlugin_Projection::ID()))
+      aToUseZLayer = true;
     Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
     if (!aDim.IsNull()) {
-      aCtx->SetZLayer(aDim, myVisualLayerId);
+      aToUseZLayer = true;
     } else {
       Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
       if (!aCons.IsNull())
-        aCtx->SetZLayer(aCons, myVisualLayerId);
+      aToUseZLayer = true;
     }
+    aCtx->SetZLayer(anAIS, myVisualLayerId);
   }
 }
 
@@ -982,28 +1010,33 @@ void PartSet_Module::onViewTransformed(int theTrsfType)
   }
   if (aView.IsNull())
     return;
-  double aLen = aView->Convert(SketcherPrs_Tools::getDefaultArrowSize());
-
-  double aPrevLen = SketcherPrs_Tools::getArrowSize();
-  SketcherPrs_Tools::setArrowSize(aLen);
-  const double aPrevScale = aViewer->Scale(aViewer->activeView());
-  const double aCurScale = aViewer->activeView()->Camera()->Scale();
-  aViewer->SetScale(aViewer->activeView(), aCurScale);
-  SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
-  bool isModified = false;
-  QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
-  foreach (AISObjectPtr aAIS, aPrsList) {
-    Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
-
-    Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
-    if (!aDim.IsNull()) {
-      aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
-      aContext->Redisplay(aDim, false);
-      isModified = true;
+
+  ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
+  if (aCurrentOperation &&
+    (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
+     sketchMgr()->isNestedSketchOperation(aCurrentOperation)))
+  {
+    double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
+
+    double aPrevLen = SketcherPrs_Tools::getArrowSize();
+    SketcherPrs_Tools::setArrowSize(aLen);
+    const double aCurScale = aViewer->activeView()->Camera()->Scale();
+    aViewer->SetScale(aViewer->activeView(), aCurScale);
+    bool isModified = false;
+    QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
+    foreach (AISObjectPtr aAIS, aPrsList) {
+      Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
+
+      Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
+      if (!aDim.IsNull()) {
+        aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
+        aContext->Redisplay(aDim, false);
+        isModified = true;
+      }
     }
+    if (isModified)
+      aDisplayer->updateViewer();
   }
-  if (isModified)
-    aDisplayer->updateViewer();
 }
 
 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
@@ -1183,8 +1216,9 @@ void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
   bool hasParameter = false;
   bool hasCompositeOwner = false;
   bool hasResultInHistory = false;
+  bool hasFolder = false;
   ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
-                                  hasCompositeOwner, hasResultInHistory);
+                                  hasCompositeOwner, hasResultInHistory, hasFolder);
 
   ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
   if (aSelected == 1) {
@@ -1471,7 +1505,7 @@ void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Messa
 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
                                      int theIndex)
 {
-  PartSet_WidgetChoice* aChoiceWidget = dynamic_cast<PartSet_WidgetChoice*>(theWidget);
+  ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
   if (!aChoiceWidget)
     return;