Salome HOME
Construction elements are auxiliary entities:
authornds <natalia.donis@opencascade.com>
Tue, 3 Mar 2015 14:34:14 +0000 (17:34 +0300)
committernds <natalia.donis@opencascade.com>
Tue, 3 Mar 2015 14:34:14 +0000 (17:34 +0300)
a boolean flag in the sketch feature,
customize sketch feature presentation by the color change.

Important modification: it was decided to use non-obligatory xml constructions to set the no-focus policy for the attribute.
Otherwise during a segment-line creation, it is not enough to select two points, the check box control has a focus after them.

src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/PartSet/PartSet_WidgetSketchLabel.h
src/SketchPlugin/SketchPlugin_Feature.h
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/plugin-Sketch.xml

index a4368946be30ddbfe501965959559300eb6e3487..2085e690202290fa5c6e6457f5bccaa6d4587ee5 100644 (file)
@@ -31,6 +31,7 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
   myDefaultValue = theData->getProperty(ATTR_DEFAULT);
   myIsComputedDefault = theData->getProperty(ATTR_DEFAULT) == DOUBLE_WDG_DEFAULT_COMPUTED;
   myAttributeID = theData ? theData->widgetId() : "";
+  myIsObligatory = theData->getBooleanAttribute(ATTR_OBLIGATORY, true);
 
   connect(this, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
 }
@@ -44,8 +45,13 @@ void ModuleBase_ModelWidget::enableFocusProcessing()
 {
   QList<QWidget*> aMyControls = getControls();
   foreach(QWidget*  eachControl, aMyControls) {
-    eachControl->setFocusPolicy(Qt::StrongFocus);
-    eachControl->installEventFilter(this);
+    if (myIsObligatory) {
+      eachControl->setFocusPolicy(Qt::StrongFocus);
+      eachControl->installEventFilter(this);
+    }
+    else {
+      eachControl->setFocusPolicy(Qt::NoFocus);
+    }
   }
 }
 
@@ -85,14 +91,15 @@ bool ModuleBase_ModelWidget::focusTo()
 {
   QList<QWidget*> aControls = getControls();
   QList<QWidget*>::const_iterator anIt = aControls.begin(), aLast = aControls.end();
-  for (; anIt != aLast; anIt++) {
+  bool isFocusAccepted = false;
+  for (; anIt != aLast && !isFocusAccepted; anIt++) {
     QWidget* aWidget = *anIt;
     if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) {
       aWidget->setFocus();
-      break;
+      isFocusAccepted = true;
     }
   }
-  return true;
+  return isFocusAccepted;
 }
 
 void ModuleBase_ModelWidget::activate()
index 03067aa6810463257d3c92438816957ca870ff49..80b1773a327d8c6a93ce7531d01f63619f90619c 100644 (file)
@@ -96,8 +96,9 @@ Q_OBJECT
   /// FocusIn events processing
   virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
 
-  //! \brief Enables processing of focus event on all controls by the widget
-  void enableFocusProcessing();
+  /// \brief Enables processing of focus event on all controls by the widget
+  /// if this widget is not obligatory and set no-focus policy otherwise
+  virtual void enableFocusProcessing();
 
   //! Switch On/Off highlighting of the widget
   void setHighlighted(bool isHighlighted);
@@ -197,6 +198,10 @@ protected slots:
   /// Flag which shows that current operation is in editing mode
   bool myIsEditing; 
 
+  /// Flag which shows whether current widget is obligatory
+  /// The non-obligatory widgets should not accept the focus in the property panel
+  bool myIsObligatory;
+
 private:
   /// Value should be computed on execute, like radius for circle's constraint (can not be zero)
   bool myIsComputedDefault; 
index 8288bdf82ac54d8248693eaa42f5c28682cc668f..1189dd2286ce32c64c8699f6793b89a27fdb7246 100644 (file)
@@ -70,6 +70,9 @@ Q_OBJECT
   /// Returns sketcher plane
   std::shared_ptr<GeomAPI_Pln> plane() const;
 
+  /// This control accepts focus
+  virtual bool focusTo() { return true; }
+
 signals:
   /// Signal on plane selection
   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
index 076b1d038f3f5456a92aef3b17fc5ef6a66bf932..9e22b9ce812c3472fd1fe948c55b4ec6106cb57e 100644 (file)
@@ -13,6 +13,7 @@
 #include <GeomAPI_AISObject.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeBoolean.h>
 #include <GeomAPI_ICustomPrs.h>
 
 #include <Config_PropManager.h>
@@ -20,6 +21,7 @@
 #define SKETCH_EDGE_COLOR "#ff0000"
 #define SKETCH_POINT_COLOR "#ff0000"
 #define SKETCH_EXTERNAL_EDGE_COLOR "#00ff00"
+#define SKETCH_CONSTRUCTION_COLOR "#000000"
 
 class SketchPlugin_Sketch;
 class GeomAPI_Pnt2d;
@@ -33,6 +35,13 @@ class Handle_AIS_InteractiveObject;
 class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
 {
  public:
+  /// Reference to the construction type of the feature
+  inline static const std::string& CONSTRUCTION_ID()
+  {
+    static const std::string MY_CONSTRUCTION_ID("Construction");
+    return MY_CONSTRUCTION_ID;
+  }
+
   /// Reference to the external edge or vertex as a AttributeSelection
   inline static const std::string& EXTERNAL_ID()
   {
@@ -74,28 +83,39 @@ class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
   virtual void customisePresentation(AISObjectPtr thePrs)
   {
     std::vector<int> aRGB;
-    // if this is an edge
-    if (thePrs->getShapeType() == 6) {
-      thePrs->setWidth(3);
-      if (isExternal()) {
-        // Set color from preferences
-        aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
-                                         SKETCH_EXTERNAL_EDGE_COLOR);
+  
+    int aShapeType = thePrs->getShapeType();
+    if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
+      return;
+
+    bool isConstruction = data()->boolean(SketchPlugin_Feature::CONSTRUCTION_ID())->value();
+    if (aShapeType == 6) { // if this is an edge
+      if (isConstruction) {
+        thePrs->setWidth(1);
+        aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
+                                         SKETCH_CONSTRUCTION_COLOR);
       }
       else {
-        // Set color from preferences
-        aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
-                                         SKETCH_EDGE_COLOR);
+        thePrs->setWidth(3);
+        if (isExternal()) {
+          // Set color from preferences
+          aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
+                                           SKETCH_EXTERNAL_EDGE_COLOR);
+        }
+        else {
+          // Set color from preferences
+          aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
+                                           SKETCH_EDGE_COLOR);
+        }
       }
     }
-    else if (thePrs->getShapeType() == 7) { // otherwise this is a vertex
+    else if (aShapeType == 7) { // otherwise this is a vertex
+      //  thePrs->setPointMarker(6, 2.);
       // Set color from preferences
       aRGB = Config_PropManager::color("Visualization", "sketch_point_color",
                                        SKETCH_POINT_COLOR);
     }
-    // if this is a vertex
-    //else if (thePrs->getShapeType() == 7)
-    //  thePrs->setPointMarker(6, 2.);
+
     if (!aRGB.empty())
       thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
   }
index 429f7e132cf55ae41fcd7a55d8ba8f85af136eb4..ee7193e72b5d7b24ecda26152b6fe58134500c4f 100644 (file)
@@ -9,6 +9,7 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
 
@@ -29,6 +30,7 @@ void SketchPlugin_Line::initAttributes()
 {
   data()->addAttribute(START_ID(), GeomDataAPI_Point2D::type());
   data()->addAttribute(END_ID(), GeomDataAPI_Point2D::type());
+  data()->addAttribute(CONSTRUCTION_ID(), ModelAPI_AttributeBoolean::type());
   data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
 }
index 20958c5e387540b81a96e000d6c150badd84cff8..aeaba71c8199b8553d928c49b616de542fe7f333 100644 (file)
@@ -66,6 +66,9 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
   Config_PropManager::registerProp("Visualization", "sketch_external_color", "Sketch external edge color",
                                    Config_Prop::Color, SKETCH_EXTERNAL_EDGE_COLOR);
 
+  Config_PropManager::registerProp("Visualization", "sketch_construction_color", "Sketch construction color",
+                                   Config_Prop::Color, SKETCH_CONSTRUCTION_COLOR);
+
   Config_PropManager::registerProp("Visualization", "sketch_parallel_color", "Sketch constraint color",
                                    Config_Prop::Color, SKETCH_CONSTRAINT_COLOR);
   Config_PropManager::registerProp("Visualization", "sketch_dimension_color", "Sketch dimension color",
index 753b225bedf073a8fd518c3f56598257c86b4c41..ff6c30559b749debe6de24c602257285d68b6ac3 100644 (file)
@@ -19,6 +19,7 @@
       <feature id="SketchLine" title="Line" tooltip="Create a new line" icon=":icons/line.png">
         <sketch-2dpoint_selector id="StartPoint" title="Start point" tooltip="Start point coordinates" previous_feature_param="EndPoint"/>
         <sketch-2dpoint_selector id="EndPoint" title="End point" tooltip="End point coordinates"/>
+        <boolvalue id="Construction" label="Construction" default="false" tooltip="Construction element" obligatory="0"/>
       </feature>
       <feature id="SketchCircle" title="Circle" tooltip="Create a new circle" icon=":icons/circle.png">
         <sketch-2dpoint_selector id="CircleCenter" title="Center" tooltip="Center coordinates"/>