]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
using the previous type of Circle/Arc during reentrant operation. First correction...
authornds <nds@opencascade.com>
Fri, 12 Feb 2016 18:27:43 +0000 (21:27 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:04:46 +0000 (17:04 +0300)
src/ModuleBase/ModuleBase_IPropertyPanel.cpp
src/ModuleBase/ModuleBase_ToolBox.cpp
src/ModuleBase/ModuleBase_ToolBox.h
src/PartSet/PartSet_OperationPrs.cpp
src/PartSet/PartSet_SketcherReetntrantMgr.cpp
src/PartSet/PartSet_SketcherReetntrantMgr.h
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_Arc.h
src/SketchPlugin/SketchPlugin_Circle.h
src/SketchPlugin/plugin-Sketch.xml

index 0a87a74c838943d7ac01623d9f3a38c3e125d149..c37673303ecbfd26953efe867ab139dfc33c0e08 100644 (file)
@@ -9,6 +9,10 @@
 
 #include "ModuleBase_IPropertyPanel.h"
 #include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_ToolBox.h"
+
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
 
 ModuleBase_IPropertyPanel::ModuleBase_IPropertyPanel(QWidget* theParent) : QDockWidget(theParent), myIsEditing(false)
 {
@@ -25,12 +29,24 @@ ModuleBase_ModelWidget* ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
 {
   ModuleBase_ModelWidget* aFirstWidget = 0;
 
+  ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
+
   ModuleBase_ModelWidget* aWgt;
   QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
+  bool isOffToolBox = false;
   for (aWIt = theWidgets.begin(); aWIt != theWidgets.end() && !aFirstWidget; ++aWIt) {
     aWgt = (*aWIt);
-    if (aWgt->canSetValue())
-      aFirstWidget = aWgt;
+    if (!aValidators->isCase(aWgt->feature(), aWgt->attributeID()))
+      continue; // this attribute is not participated in the current case
+
+    if (!aWgt->canSetValue())
+      continue;
+
+    /// workaround for the same attributes used in different stacked widgets(attribute types)
+    if (ModuleBase_ToolBox::isOffToolBoxParent(aWgt))
+      continue;
+
+    aFirstWidget = aWgt;
   }
   return aFirstWidget;
 }
index 57c7332c6f85f9822553f3bb4940c51ed4c74549..1ab883c86e13653ada9d70bf36bf1c98dec7d87b 100644 (file)
@@ -5,6 +5,8 @@
 // Author:      Alexandre SOLOVYOV
 
 #include <ModuleBase_ToolBox.h>
+#include <ModuleBase_ModelWidget.h>
+
 #include <QButtonGroup>
 #include <QStackedWidget>
 #include <QHBoxLayout>
@@ -76,3 +78,26 @@ void ModuleBase_ToolBox::onButton( int theIndex )
   myStack->setCurrentIndex( theIndex );
 }
 
+bool ModuleBase_ToolBox::isOffToolBoxParent(ModuleBase_ModelWidget* theWidget)
+{
+  bool isOffToolBox = false;
+
+  QList<QWidget*> aControls = theWidget->getControls();
+  if (aControls.size() > 0) {
+    QWidget* aFirstControl = aControls.first();
+
+    QWidget* aWidget = aFirstControl;
+    QWidget* aParent = (QWidget*)aFirstControl->parent();
+    while (aParent) {
+      QStackedWidget* aStackedWidget = dynamic_cast<QStackedWidget*>(aParent);
+      if (aStackedWidget) {
+        int anIndex = aStackedWidget->currentIndex();
+        isOffToolBox = aStackedWidget->currentWidget() != aWidget;
+        break;
+      }
+      aWidget = aParent;
+      aParent = (QWidget*)aWidget->parent();
+    }
+  }
+  return isOffToolBox;
+}
index 1c2c1ef7d37df2cf6cc859207c2311589ccfe076..cab3a788d93399d0a0a5fd2777e24943c1ec8817 100644 (file)
@@ -14,6 +14,7 @@ class QButtonGroup;
 class QFrame;
 class QHBoxLayout;
 class QStackedWidget;
+class ModuleBase_ModelWidget;
 
 /**
  * \class ModuleBase_ToolBox
@@ -46,6 +47,12 @@ public:
   /// \param theIdx an index
   void setCurrentIndex( const int theIdx);
 
+  /// Found in the controls of the model widget parent in Stacked Widget
+  /// returns whether this controls are in the current widget of the stacked widgets
+  /// \param theWidget a model widget
+  /// \return boolean result
+  static bool isOffToolBoxParent(ModuleBase_ModelWidget* theWidget);
+
 signals:
   /// A signal which is emited on current item changed
   void currentChanged( int );
index aa12287afaf7254f7245484fcbf1940967297287..fc67747b98581b2be18c132b46655ca799c6bd50 100755 (executable)
@@ -121,7 +121,7 @@ bool PartSet_OperationPrs::isVisible(XGUI_Displayer* theDisplayer, const ObjectP
     aVisible = theDisplayer->isVisible(theObject);
     // compsolid is not visualized in the viewer, but should have presentation when all sub solids are
     // visible. It is useful for highlight presentation where compsolid shape is selectable
-    if (!aVisible && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
+    if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
       ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
       if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
         bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
index 15cf843d3072df5989d5dd1d08db2db2f0d81a1e..93f706d46847589a70430d358b5daa5410363021 100755 (executable)
@@ -6,6 +6,7 @@
 #include "PartSet_WidgetPoint2d.h"
 
 #include "ModelAPI_Session.h"
+#include "ModelAPI_AttributeString.h"
 
 #include <ModuleBase_IPropertyPanel.h>
 #include <ModuleBase_OperationFeature.h>
@@ -19,6 +20,8 @@
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Line.h>
+#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_Circle.h>
 
 #include <XGUI_Workshop.h>
 #include <XGUI_ModuleConnector.h>
@@ -47,9 +50,9 @@ ModuleBase_ModelWidget* PartSet_SketcherReetntrantMgr::internalActiveWidget() co
   if (!isActiveMgr())
     return aWidget;
 
-  ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
-  if (aOperation) {
-    ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+  ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+  if (anOperation) {
+    ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
     if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector()))
       aWidget = myInternalActiveWidget;
@@ -233,15 +236,33 @@ bool PartSet_SketcherReetntrantMgr::processEnter(const std::string& thePreviousA
   return isDone;
 }
 
+/*bool isTangentArc(ModuleBase_Operation* theOperation)
+{
+  bool aTangentArc = false;
+  ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+                                                                        (theOperation);
+  if (aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)) {
+    FeaturePtr aFeature = aFOperation->feature();
+    if (aFeature.get() && aFeature->getKind() == SketchPlugin_Arc::ID()) {
+      AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_Arc::ARC_TYPE());
+      std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
+      aTangentArc = anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT();
+    }
+  }
+
+  return aTangentArc;
+}*/
+
 void PartSet_SketcherReetntrantMgr::onVertexSelected()
 {
   if (!isActiveMgr())
     return;
 
-  ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
-  if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
+  ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+  std::string anOperationId = anOperation->id().toStdString();
+  if (anOperationId == SketchPlugin_Line::ID()/* || isTangentArc(anOperation)*/) {
     /// If last line finished on vertex the lines creation sequence has to be break
-    ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+    ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
     QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
@@ -375,8 +396,14 @@ void PartSet_SketcherReetntrantMgr::restartOperation()
     if (aFOperation) {
       myNoMoreWidgetsAttribute = "";
       myIsFlagsBlocked = true;
+      FeaturePtr aPrevFeature = aFOperation->feature();
       aFOperation->commit();
       module()->launchOperation(aFOperation->id());
+      // allow the same attribute values in restarted operation
+      ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast<ModuleBase_OperationFeature*>(
+                                                                  myWorkshop->currentOperation());
+      copyReetntrantAttributes(aPrevFeature, aCurrentOperation->feature());
+
       myIsFlagsBlocked = false;
       resetFlags();
       // we should avoid processing of the signal about no more widgets attributes and 
@@ -391,6 +418,27 @@ void PartSet_SketcherReetntrantMgr::restartOperation()
   }
 }
 
+bool PartSet_SketcherReetntrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
+                                                             const FeaturePtr& theNewFeature)
+{
+  bool aChanged;
+  std::string aTypeAttributeId;
+  if (theSourceFeature->getKind() == SketchPlugin_Circle::ID()) {
+    aTypeAttributeId = SketchPlugin_Circle::CIRCLE_TYPE();
+  }
+  if (theSourceFeature->getKind() == SketchPlugin_Arc::ID()) {
+    aTypeAttributeId = SketchPlugin_Arc::ARC_TYPE();
+  }
+  if (!aTypeAttributeId.empty()) {
+    AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
+    AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
+    aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
+    ModuleBase_ModelWidget::updateObject(theNewFeature);
+    aChanged = true;
+  }
+  return aChanged;
+}
+
 void PartSet_SketcherReetntrantMgr::createInternalFeature()
 {
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
@@ -401,6 +449,8 @@ void PartSet_SketcherReetntrantMgr::createInternalFeature()
 
     CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
     myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
+
+    bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature);
     XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
                                                   (aFOperation->propertyPanel());
 
@@ -420,7 +470,10 @@ void PartSet_SketcherReetntrantMgr::createInternalFeature()
                           !aWidget->getDefaultValue().empty() &&
                           !aWidget->isComputedDefault();
       aWidget->setFeature(myInternalFeature, isStoreValue);
+      if (!isStoreValue && isFeatureChanged)
+        aWidget->restoreValue();
     }
+
     ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
                                                                                         (aWidgets);
     if (aFirstWidget)
index ebdb0eb16b55b1178f40af4d356ec7845e1fcb9c..8f16bce6d11466442d314a9873fdb7f657d0856b 100755 (executable)
@@ -139,6 +139,14 @@ private:
   /// Breaks sequense of automatically resterted operations
   void resetFlags();
 
+  /// Copy some feature specific attributes from the source to a new feature
+  /// This is type for Circle and Arc features
+  /// \param theSourceFeature a source feature
+  /// \param theNewFeature a new feature
+  /// \return true is something is copied
+  static bool copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
+                                       const FeaturePtr& theNewFeature);
+
   /// Returns the workshop
   XGUI_Workshop* workshop() const;
 
index 2725d87904146bf25a72cdd2f73457a47c6bebea..ac9981b002ce4684a3a5921d617f1d7c321bec49 100644 (file)
@@ -42,11 +42,11 @@ const double paramTolerance = 1.e-4;
 const double PI =3.141592653589793238463;
 
 namespace {
-  static const std::string& ARC_TYPE()
+  /*static const std::string& ARC_TYPE()
   {
     static const std::string TYPE("ArcType");
     return TYPE;
-  }
+  }*/
   static const std::string& ARC_TYPE_CENTER_START_END()
   {
     static const std::string TYPE("CenterStartEnd");
@@ -57,11 +57,11 @@ namespace {
     static const std::string TYPE("ThreePoints");
     return TYPE;
   }
-  static const std::string& ARC_TYPE_TANGENT()
+  /*static const std::string& ARC_TYPE_TANGENT()
   {
     static const std::string TYPE("Tangent");
     return TYPE;
-  }
+  }*/
 
   static const std::string& PASSED_POINT_ID()
   {
@@ -140,6 +140,9 @@ void SketchPlugin_Arc::initDerivedClassAttributes()
   data()->addAttribute(TANGENT_POINT_ID(), ModelAPI_AttributeRefAttr::typeId());
   data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
+
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), RADIUS_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ANGLE_ID());
 }
 
 void SketchPlugin_Arc::execute()
index 2bd7c0c44ab7a918cc71d019af17cb03617befcb..b3cfa3a2d1fc0254a9344955c2b80754bf8b2bce 100644 (file)
@@ -38,6 +38,18 @@ class SketchPlugin_Arc : public SketchPlugin_SketchEntity, public GeomAPI_IPrese
     return MY_SKETCH_ARC_ID;
   }
 
+  inline static const std::string& ARC_TYPE()
+  {
+    static const std::string TYPE("ArcType");
+    return TYPE;
+  }
+
+  inline static const std::string& ARC_TYPE_TANGENT()
+  {
+    static const std::string TYPE("Tangent");
+    return TYPE;
+  }
+
   /// Central 2D point of the circle which contains the arc
   inline static const std::string& CENTER_ID()
   {
index daf4d2651eacb7d921a8b901271a4757d6331c9f..b6d01897eb99ee2c0d4af35d41cc6694a6240a4b 100644 (file)
@@ -26,6 +26,12 @@ class SketchPlugin_Circle : public SketchPlugin_SketchEntity, public GeomAPI_IPr
     return MY_CIRCLE_ID;
   }
 
+  inline static const std::string& CIRCLE_TYPE()
+  {
+    static const std::string TYPE("CircleType");
+    return TYPE;
+  }
+
   /// 2D point - center of the circle
   inline static const std::string& CENTER_ID()
   {
index c654a5535eda30e6b26869e306c6970713a4744e..24d946c1fc6ad8ad939fe3e5e40c5c0554954024 100644 (file)
             <point2ddistance id="CircleRadius" accept_expressions="0" first_point="CircleCenter" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set radius">
               <validator id="GeomValidators_Positive"/>
             </point2ddistance>
-            <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
           </box>
           <box id="ThreePoints" title="Three points" icon=":icons/circle_3pt_32x32.png">
             <sketch-2dpoint_selector id="FirstPoint" accept_expressions="0" title="First point" tooltip="First point"/>
             <sketch-2dpoint_selector id="SecondPoint" accept_expressions="0" title="Second point" tooltip="Second point"/>
             <sketch-2dpoint_selector id="ThirdPoint" accept_expressions="0" title="Third point" tooltip="Third point"/>
-            <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
           </box>
         </toolbox>
+        <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
       </feature>
 
       <!-- SketchArc -->
             <sketch-2dpoint_selector id="ArcCenter" accept_expressions="0" title="Center" tooltip="Center of a circle"/>
             <sketch-2dpoint_selector id="ArcStartPoint" accept_expressions="0" title="Start point" tooltip="Start point"/>
             <sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"/>
-            <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
             <validator id="GeomValidators_Different" parameters="ArcCenter,ArcStartPoint,ArcEndPoint"/>
           </box>
           <box id="ThreePoints" title="Three points on arc" icon=":icons/arc_3pt_32x32.png">
             <sketch-2dpoint_selector id="ArcStartPoint" accept_expressions="0" title="Start point" tooltip="Start point"/>
             <sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"/>
             <sketch-2dpoint_selector id="ArcPassedPoint" accept_expressions="0" title="Passed point" tooltip="Passed point"/>
-            <doublevalue id="ArcRadius" accept_expressions="0" label="Radius:" default="computed" icon=":icons/radius.png" tooltip="Set radius" obligatory="1">
+            <doublevalue id="ArcRadius" accept_expressions="0" label="Radius:" default="computed" icon=":icons/radius.png" tooltip="Set radius" obligatory="0">
               <validator id="GeomValidators_Positive"/>
             </doublevalue>
-            <doublevalue id="ArcAngle" label="Angle:" icon=":icons/angle.png" tooltip="Set angle" default="90" use_reset="false" obligatory="1"/>
-            <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
+            <doublevalue id="ArcAngle" label="Angle:" icon=":icons/angle.png" tooltip="Set angle" default="90" use_reset="false" obligatory="0"/>
             <validator id="GeomValidators_Different" parameters="ArcStartPoint,ArcEndPoint,ArcPassedPoint"/>
           </box>
           <box id="Tangent" title="Tangent with edge" icon=":icons/arc_tang_32x32.png">
               <validator id="SketchPlugin_ArcTangentPoint" parameters="" />
             </sketch_shape_selector>
             <sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"/>
-            <doublevalue id="ArcRadius" accept_expressions="0" label="Radius:" default="computed" icon=":icons/radius.png" tooltip="Set radius" obligatory="1">
+            <doublevalue id="ArcRadius" accept_expressions="0" label="Radius:" default="computed" icon=":icons/radius.png" tooltip="Set radius" obligatory="0">
               <validator id="GeomValidators_Positive"/>
             </doublevalue>
-            <doublevalue id="ArcAngle" label="Angle:" icon=":icons/angle.png" tooltip="Set angle" default="90" use_reset="false" obligatory="1"/>
-            <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
+            <doublevalue id="ArcAngle" label="Angle:" icon=":icons/angle.png" tooltip="Set angle" default="90" use_reset="false" obligatory="0"/>
           </box>
         </toolbox>
+        <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
       </feature>
     </group>