Salome HOME
Issue #1664 In the Sketcher, add the function Split a segment
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Line.cpp
index 3c4e19a1a369fe247dc140a81cc63c6815924cc3..782f99a2472346eed9e2e785846da018e28853ca 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());
 }
 
@@ -118,7 +123,13 @@ void SketchPlugin_Line::attributeChanged(const std::string& theID) {
   // to be removed after debug
   if ((theID == EXTERNAL_ID() || isFixed()) && !isCopy()) {
     std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(EXTERNAL_ID())->value();
-     // update arguments due to the selection value
+    if (!aSelection) {
+      // empty shape in selection shows that the shape is equal to context
+      ResultPtr anExtRes = selection(EXTERNAL_ID())->context();
+      if (anExtRes)
+        aSelection = anExtRes->shape();
+    }
+    // update arguments due to the selection value
     if (aSelection && !aSelection->isNull() && aSelection->isEdge()) {
       std::shared_ptr<GeomAPI_Edge> anEdge( new GeomAPI_Edge(aSelection));
       std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = 
@@ -137,7 +148,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 +156,4 @@ void SketchPlugin_Line::updateLenghtValue()
     double aDistance = aStartAttr->pnt()->distance(anEndAttr->pnt());
     data()->real(LENGTH_ID())->setValue(aDistance);
   }
-#endif
 }