]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/PartSet/PartSet_Module.cpp
Salome HOME
Avoid crash on clearing of a document by a script
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index bd06498f248abf9d2747e21fd145764205ea3efa..aa7b4e383f47e0d4298d138e4c26fb6407b0a877 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"
@@ -46,6 +47,8 @@
 #include <PartSetPlugin_Part.h>
 #include <PartSetPlugin_Duplicate.h>
 
+#include <SketchPlugin_ConstraintCoincidence.h>
+
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationAction.h>
 #include <ModuleBase_IViewer.h>
@@ -150,6 +153,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();
@@ -205,6 +209,23 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
                                    "Hidden faces transparency",
                                    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",
+    "Dimension color",
+    Config_Prop::Color, SKETCH_DIMENSION_COLOR);
 }
 
 //******************************************************
@@ -219,8 +240,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()
 {
@@ -1060,7 +1091,10 @@ void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
       }
       if (aToUseZLayer) {
         Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
-        aCtx->SetZLayer(anAIS, myVisualLayerId);
+        if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
+          aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
+        else
+          aCtx->SetZLayer(anAIS, myVisualLayerId);
       }
     }
   }
@@ -1108,10 +1142,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 +1155,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 +1173,7 @@ void PartSet_Module::onViewTransformed(int theTrsfType)
     if (isModified)
       aDisplayer->updateViewer();
   }
+
 }
 
 //******************************************************
@@ -1219,11 +1259,6 @@ bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result>
   // customize sketch dimension constraint presentation
   if (!aCustomized) {
     if (!aColor.empty()) { // otherwise presentation has the default color
-      AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
-      aColorAttr->setSize(3);
-      // Set the color attribute in order do not use default colors in the perasentation object
-      for (int i = 0; i < 3; i++)
-        aColorAttr->setValue(i, aColor[i]);
       aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
     }
   }
@@ -1407,11 +1442,15 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
 
     SessionPtr aMgr = ModelAPI_Session::get();
     DocumentPtr aActiveDoc = aMgr->activeDocument();
-    // workaround for #2431 (SISGSEGV when launching some unit tests from GUI)
-    //if (myActivePartIndex.isValid())
-    //  aTreeView->setExpanded(myActivePartIndex, false);
+
+    // Clear active part index if there is no Part documents
+    // It could be not null if document was closed and opened a new
+    // without closeDocument call
+    if (aMgr->allOpenedDocuments().size() <= 1)
+      myActivePartIndex = QModelIndex();
 
     XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
+    QModelIndex aOldActive = myActivePartIndex;
     myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
     bool needUpdate = false;
     if (myActivePartIndex.isValid()) {
@@ -1419,6 +1458,8 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
       if (!needUpdate)
         aTreeView->setExpanded(myActivePartIndex, true);
     }
+    if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
+      aTreeView->setExpanded(aOldActive, false);
 
     aLabel->setPalette(aPalet);
     aWorkshop->updateCommandStatus();
@@ -1636,10 +1677,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;
+}