Salome HOME
Meet the coding style (line length <= 100)
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_IntersectionPoint.cpp
index 5c411427c1463dcaab3d427ace30188f567beb2b..a71c02499b3d20b8a3c95fcaab2fdbaed182e4a8 100644 (file)
@@ -6,7 +6,9 @@
 
 #include "SketchPlugin_IntersectionPoint.h"
 
-#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
 
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Lin.h>
@@ -19,7 +21,7 @@ SketchPlugin_IntersectionPoint::SketchPlugin_IntersectionPoint()
 
 void SketchPlugin_IntersectionPoint::initDerivedClassAttributes()
 {
-  data()->addAttribute(EXTERNAL_LINE_ID(), ModelAPI_AttributeRefAttr::typeId());
+  data()->addAttribute(EXTERNAL_LINE_ID(), ModelAPI_AttributeSelection::typeId());
 
   SketchPlugin_Point::initDerivedClassAttributes();
 }
@@ -50,22 +52,27 @@ void SketchPlugin_IntersectionPoint::attributeChanged(const std::string& theID)
 
 void SketchPlugin_IntersectionPoint::computePoint()
 {
-  AttributeRefAttrPtr aLineRefAttr =
-      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(attribute(EXTERNAL_LINE_ID()));
-  ResultPtr aLineResult = std::dynamic_pointer_cast<ModelAPI_Result>(aLineRefAttr->object());
-  if (!aLineResult)
+  AttributeSelectionPtr aLineAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(attribute(EXTERNAL_LINE_ID()));
+
+  std::shared_ptr<GeomAPI_Edge> anEdge;
+  if(aLineAttr && aLineAttr->value() && aLineAttr->value()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLineAttr->value()));
+  } else if(aLineAttr->context() && aLineAttr->context()->shape() &&
+            aLineAttr->context()->shape()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLineAttr->context()->shape()));
+  }
+  if(!anEdge.get())
     return;
 
-  std::shared_ptr<GeomAPI_Edge> aLinearEdge =
-      std::dynamic_pointer_cast<GeomAPI_Edge>(aLineResult->shape());
-  std::shared_ptr<GeomAPI_Lin> aLine = aLinearEdge->line();
+  std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
   std::shared_ptr<GeomAPI_Pln> aSketchPlane = sketch()->plane();
 
   std::shared_ptr<GeomAPI_Pnt> anIntersection = aSketchPlane->intersect(aLine);
   if (!anIntersection)
     return;
 
-  std::shared_ptr<GeomDataAPI_Point2D> aCoordAttr = 
+  std::shared_ptr<GeomDataAPI_Point2D> aCoordAttr =
       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(COORD_ID()));
   aCoordAttr->setValue(sketch()->to2D(anIntersection));
 }