Salome HOME
Issue #1652 Add a real widget displaying the length of the line in the panel: correct...
authornds <nds@opencascade.com>
Wed, 27 Jul 2016 15:51:10 +0000 (18:51 +0300)
committernds <nds@opencascade.com>
Wed, 27 Jul 2016 15:51:10 +0000 (18:51 +0300)
src/PartSet/PartSet_Tools.cpp
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Line.h
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/plugin-Sketch.xml

index 5e22fd68a9bb96c7c40a32c65a0db343b8c79236..6495c3ce9da85724a5727a442234f72e4c889b46 100755 (executable)
@@ -395,15 +395,18 @@ void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr the
 
 std::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch)
 {
+  std::shared_ptr<GeomAPI_Pln> aPlane;
+
   std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
       theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+  std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
       theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
 
-  if (!anOrigin || !aNorm)
-    return std::shared_ptr<GeomAPI_Pln>();
+  if (aNormal.get() && aNormal->isInitialized() &&
+      anOrigin.get() && anOrigin->isInitialized())
+    aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNormal->dir()));
 
-  return std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
+  return aPlane;
 }
 
 std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
index 3c4e19a1a369fe247dc140a81cc63c6815924cc3..2d2c6bc4a9880955de3c1f030c2b2d6cf231ed38 100644 (file)
@@ -27,14 +27,19 @@ SketchPlugin_Line::SketchPlugin_Line()
     : SketchPlugin_SketchEntity()
 {}
 
+void SketchPlugin_Line::initAttributes()
+{
+  SketchPlugin_SketchEntity::initAttributes();
+  /// new attributes should be added to end of the feature in order to provide
+  /// correct attribute values in previous saved studies
+  data()->addAttribute(LENGTH_ID(), ModelAPI_AttributeDouble::typeId());
+}
+
 void SketchPlugin_Line::initDerivedClassAttributes()
 {
   data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId());
   data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId());
   data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
-#ifndef LINE_LENGHT_BLOCKED
-  data()->addAttribute(LENGTH_ID(), ModelAPI_AttributeDouble::typeId());
-#endif
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
 }
 
@@ -137,7 +142,6 @@ void SketchPlugin_Line::attributeChanged(const std::string& theID) {
 
 void SketchPlugin_Line::updateLenghtValue()
 {
-#ifndef LINE_LENGHT_BLOCKED
   std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
       GeomDataAPI_Point2D>(data()->attribute(START_ID()));
   std::shared_ptr<GeomDataAPI_Point2D> anEndAttr = std::dynamic_pointer_cast<
@@ -146,5 +150,4 @@ void SketchPlugin_Line::updateLenghtValue()
     double aDistance = aStartAttr->pnt()->distance(anEndAttr->pnt());
     data()->real(LENGTH_ID())->setValue(aDistance);
   }
-#endif
 }
index 0ff8e6b71ec3e2a2f3069733735df538eb35ed1a..e24e90e5444c0f52762a57e99e576f89258db299 100644 (file)
@@ -12,7 +12,6 @@
 #include <SketchPlugin_Sketch.h>
 #include <list>
 
-#define LINE_LENGHT_BLOCKED
 class GeomAPI_Pnt2d;
 
 /**\class SketchPlugin_Line
@@ -42,19 +41,21 @@ class SketchPlugin_Line : public SketchPlugin_SketchEntity
   }
 
   /// Line length.
-#ifndef LINE_LENGHT_BLOCKED
   static const std::string& LENGTH_ID()
   {
     static const std::string MY_LENGTH("LineLength");
     return MY_LENGTH;
   }
-#endif
+
   /// Returns the kind of a feature
   SKETCHPLUGIN_EXPORT virtual const std::string& getKind();
 
   /// Returns true is sketch element is under the rigid constraint
   SKETCHPLUGIN_EXPORT virtual bool isFixed();
 
+  /// Request for initialization of data model of the feature: adding all attributes
+  virtual void initAttributes();
+
   /// Creates a new part document if needed
   SKETCHPLUGIN_EXPORT virtual void execute();
 
index d309ce8cbe9014f150a04b11ea763c49439d02c5..d094a04c76358b305793a7db4f77000d7d30cd22 100755 (executable)
@@ -903,7 +903,7 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
     ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
                                                 aX->dir(), aDirY, aPoints);
 
-    int aCoincidentToFeature = aPoints.size();
+    int aCoincidentToFeature = (int)aPoints.size();
     if (aKind == SketchPlugin_Circle::ID())
       aValid = aCoincidentToFeature >= 2;
     else
index b8a79e1981b71b692964a9c672aa6f589da5e0ee..d6d7d909c5ed4b781616e190a5706fed688dee26 100644 (file)
@@ -31,9 +31,8 @@
                                  enable_value="enable_by_preferences"/>
         <sketch-2dpoint_selector id="EndPoint" accept_expressions="0" title="End point" tooltip="End point coordinates"
                                  enable_value="enable_by_preferences"/>
-        <!--LINE_LENGHT_BLOCKED
         <doublevalue id="LineLength" accept_expressions="0" label="Length:" default="computed" icon="icons/Sketch/distance_value.png"
-                     tooltip="Line length" obligatory="0" enable_value="false"/> -->
+                     tooltip="Line length" obligatory="0" enable_value="false"/>
         <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
         <validator id="GeomValidators_Different" parameters="StartPoint,EndPoint"/>
       </feature>
           <box id="CenterRadius" title="Center and radius" icon="icons/Sketch/circle_pt_rad_32x32.png">
             <sketch-2dpoint_selector id="CircleCenter" accept_expressions="0" title="Center" tooltip="Center coordinates"
                                      enable_value="enable_by_preferences"/>
-            <point2ddistance id="CircleRadius" accept_expressions="0" first_point="CircleCenter" label="Radius:" min="0" step="1.0"
-                             default="0" icon="icons/Sketch/radius.png" tooltip="Set radius"
-                             enable_value="enable_by_preferences">
-              <validator id="GeomValidators_Positive"/>
-            </point2ddistance>
           </box>
           <box id="ThreePoints" title="Three points" icon="icons/Sketch/circle_3pt_32x32.png">
             <sketch-2dpoint_selector id="FirstPoint" accept_expressions="0" title="First point" tooltip="First point"
                                      enable_value="enable_by_preferences"/>
           </box>
         </toolbox>
+        <point2ddistance id="CircleRadius" accept_expressions="0" first_point="CircleCenter" label="Radius:" min="0" step="1.0"
+                         default="0" icon="icons/Sketch/radius.png" tooltip="Set radius"
+                         enable_value="enable_by_preferences">
+          <validator id="GeomValidators_Positive"/>
+        </point2ddistance>
         <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
       </feature>