Salome HOME
Correct misprint
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index b6a259050fd300695dac1144703cefb0bbe2bbb0..544d4b5c5a36d3b5fbd8a14bd5d43ab7d3704068 100755 (executable)
@@ -38,6 +38,7 @@
 #include "PartSet_CustomPrs.h"
 #include "PartSet_IconFactory.h"
 #include "PartSet_OverconstraintListener.h"
+#include "PartSet_TreeNodes.h"
 
 #include "PartSet_Filters.h"
 #include "PartSet_FilterInfinite.h"
@@ -71,6 +72,7 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeIntArray.h>
 
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Point.h>
 #include <SketchPlugin_Sketch.h>
 
 #include <SketcherPrs_SymbolPrs.h>
+#include <SketcherPrs_PositionMgr.h>
 #include <SketcherPrs_Coincident.h>
 #include <SketcherPrs_Tools.h>
 
@@ -148,6 +151,7 @@ extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop*
 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
 : ModuleBase_IModule(theWshop),
   myVisualLayerId(0),
+  myRoot(0),
   myIsOperationIsLaunched(false)
 {
   new PartSet_IconFactory();
@@ -201,14 +205,31 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
 
   Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
                                    "Hidden faces transparency",
-                                   Config_Prop::Double,
+                                   Config_Prop::DblSpin,
                                    "0.8");
+  std::ostringstream aStream;
+  aStream << SketcherPrs_Tools::getDefaultArrowSize();
+  Config_PropManager::registerProp("Visualization", "dimension_arrow_size",
+    "Dimension arrow size", Config_Prop::IntSpin, aStream.str());
+
+  Config_PropManager::registerProp("Visualization", "dimension_font", "Dimension font",
+    Config_Prop::String, "Times-bold");
+
+  aStream.str("");
+  aStream.clear();
+  aStream << SketcherPrs_Tools::getDefaultTextHeight();
+  Config_PropManager::registerProp("Visualization", "dimension_value_size",
+    "Dimension value size", Config_Prop::IntSpin, aStream.str());
+
+  Config_PropManager::registerProp("Visualization", "sketch_dimension_color",
+    "Sketch dimension color",
+    Config_Prop::Color, SKETCH_DIMENSION_COLOR);
 }
 
 //******************************************************
 PartSet_Module::~PartSet_Module()
 {
-  std::map<PartSet_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
+  std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
     mySelectionFilters.begin();
   for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
     Handle(SelectMgr_Filter) aFilter = aFiltersIt->second;
@@ -217,8 +238,18 @@ PartSet_Module::~PartSet_Module()
   }
   delete myCustomPrs;
   delete myOverconstraintListener;
+  delete myRoot;
+}
+
+//******************************************************
+void PartSet_Module::createFeatures()
+{
+  ModuleBase_IModule::createFeatures();
+  myRoot = new PartSet_RootNode();
+  myRoot->setWorkshop(workshop());
 }
 
+
 //******************************************************
 void PartSet_Module::storeSelection()
 {
@@ -264,6 +295,7 @@ void PartSet_Module::registerValidators()
     new PartSet_MultyTranslationSelection);
   aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
   aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
+  aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
 }
 
 //******************************************************
@@ -621,12 +653,9 @@ void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
                                             SelectMgr_ListOfFilter& theSelectionFilters)
 {
-  bool isSketchActive = mySketchMgr->activeSketch();
-  XGUI_ActiveControlSelector* anActiveSelector = getWorkshop()->activeControlMgr()->activeSelector();
-  bool isHideFacesActive = anActiveSelector &&
-                           anActiveSelector->getType() == XGUI_FacesPanelSelector::Type();
+  bool isSketchActive = mySketchMgr->activeSketch().get();
 
-  std::map<PartSet_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
+  std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
     mySelectionFilters.begin();
   for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
     int aFilterType = aFiltersIt->first;
@@ -636,11 +665,11 @@ void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
 
     // using sketch filters only if sketch operation is active
     if (!isSketchActive &&
-        mySketchMgr->sketchSelectionFilter((PartSet_SelectionFilterType)aFilterType))
+        mySketchMgr->sketchSelectionFilter((XGUI_SelectionFilterType)aFilterType))
       continue;
 
-    // using filtering of construction results only when faces panel is active
-    if (aFilterType == SF_ResultGroupNameFilter && !isHideFacesActive)
+    // using filtering of construction results only from faces panel
+    if (aFilterType == SF_ResultGroupNameFilter)
       continue;
 
     theSelectionFilters.Append(aFiltersIt->second);
@@ -652,7 +681,7 @@ QIntList PartSet_Module::selectionFilters()
 {
   QIntList aTypes;
 
-  std::map<PartSet_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
+  std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
     mySelectionFilters.begin();
   for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++)
     aTypes.append(aFiltersIt->first);
@@ -661,18 +690,19 @@ QIntList PartSet_Module::selectionFilters()
 }
 
 //******************************************************
-void PartSet_Module::registerSelectionFilter(const PartSet_SelectionFilterType theFilterType,
+void PartSet_Module::registerSelectionFilter(const XGUI_SelectionFilterType theFilterType,
                                              const Handle(SelectMgr_Filter)& theFilter)
 {
   mySelectionFilters[theFilterType] = theFilter;
 }
 
 //******************************************************
-Handle(SelectMgr_Filter) PartSet_Module::selectionFilter(
-  const PartSet_SelectionFilterType theFilterType)
+Handle(SelectMgr_Filter) PartSet_Module::selectionFilter(const int theType)
 {
-  if (mySelectionFilters.find(theFilterType) != mySelectionFilters.end())
-    return mySelectionFilters[theFilterType];
+  XGUI_SelectionFilterType aType = (XGUI_SelectionFilterType)theType;
+
+  if (mySelectionFilters.find(aType) != mySelectionFilters.end())
+    return mySelectionFilters[aType];
   else
     return Handle(SelectMgr_Filter)();
 }
@@ -723,6 +753,7 @@ bool PartSet_Module::isSketchNeutralPointActivated() const
 void PartSet_Module::closeDocument()
 {
   myActivePartIndex = QModelIndex();
+  SketcherPrs_PositionMgr::get()->clearAll();
 }
 
 //******************************************************
@@ -908,15 +939,15 @@ ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
 {
   ModuleBase_ModelWidget* anActiveWidget = 0;
 
-  anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
-  if (!anActiveWidget) {
-    ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
-    if (aOperation) {
-      ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
-      anActiveWidget = aPanel ? aPanel->activeWidget() : 0;
-    }
-  }
-  return anActiveWidget;
+  ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
+  if (!aOperation)
+    return anActiveWidget;
+
+  ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+  if (!aPanel)
+    return anActiveWidget;
+
+  return aPanel->activeWidget(true);
 }
 
 //******************************************************
@@ -1047,22 +1078,20 @@ 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()) {
-      aToUseZLayer = true;
-    } else {
-      Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
-      if (!aCons.IsNull())
-      aToUseZLayer = true;
+    if (aFeature.get()) {
+      bool aToUseZLayer = false;
+      if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
+        aToUseZLayer = true;
+      else {
+        CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
+        aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
+      }
+      if (aToUseZLayer) {
+        Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
+        aCtx->SetZLayer(anAIS, myVisualLayerId);
+      }
     }
-    if (aToUseZLayer)
-      aCtx->SetZLayer(anAIS, myVisualLayerId);
   }
 }
 
@@ -1108,10 +1137,12 @@ void PartSet_Module::onViewTransformed(int theTrsfType)
   if (aView.IsNull())
     return;
 
+  bool isModified = false;
   ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
   if (aCurrentOperation &&
     (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
-     sketchMgr()->isNestedSketchOperation(aCurrentOperation)))
+     sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
+     (aCurrentOperation->id() == "Measurement")))
   {
     double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
 
@@ -1119,11 +1150,14 @@ void PartSet_Module::onViewTransformed(int theTrsfType)
     SketcherPrs_Tools::setArrowSize(aLen);
     const double aCurScale = aViewer->activeView()->Camera()->Scale();
     aViewer->SetScale(aViewer->activeView(), aCurScale);
-    bool isModified = false;
+#ifdef OPTIMIZE_PRS
+    QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
+    foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
+#else
     QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
-    foreach (AISObjectPtr aAIS, aPrsList) {
+    foreach(AISObjectPtr aAIS, aPrsList) {
       Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
-
+#endif
       Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
       if (!aDim.IsNull()) {
         aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
@@ -1134,6 +1168,7 @@ void PartSet_Module::onViewTransformed(int theTrsfType)
     if (isModified)
       aDisplayer->updateViewer();
   }
+
 }
 
 //******************************************************
@@ -1402,8 +1437,9 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
 
     SessionPtr aMgr = ModelAPI_Session::get();
     DocumentPtr aActiveDoc = aMgr->activeDocument();
-    if (myActivePartIndex.isValid())
-      aTreeView->setExpanded(myActivePartIndex, false);
+    // workaround for #2431 (SISGSEGV when launching some unit tests from GUI)
+    //if (myActivePartIndex.isValid())
+    //  aTreeView->setExpanded(myActivePartIndex, false);
 
     XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
     myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
@@ -1630,10 +1666,15 @@ XGUI_Workshop* PartSet_Module::getWorkshop() const
   return aConnector->workshop();
 }
 
-//******************************************************
 void PartSet_Module::setDefaultConstraintShown()
 {
   myHasConstraintShown[PartSet_Tools::Geometrical] = true;
   myHasConstraintShown[PartSet_Tools::Dimensional] = true;
   myHasConstraintShown[PartSet_Tools::Expressions] = false;
 }
+
+//******************************************************
+ModuleBase_ITreeNode* PartSet_Module::rootNode() const
+{
+  return myRoot;
+}