1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ConstructionPlugin_Point.cxx
4 // Created: 27 Mar 2014
5 // Author: Mikhail PONIKAROV
7 #include "ConstructionPlugin_Point.h"
9 #include <ModelAPI_AttributeBoolean.h>
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_AttributeSelection.h>
12 #include <ModelAPI_AttributeString.h>
13 #include <ModelAPI_ResultConstruction.h>
15 #include <GeomAlgoAPI_PointBuilder.h>
16 #include <GeomAlgoAPI_ShapeTools.h>
18 #include <GeomAPI_Edge.h>
19 #include <GeomAPI_Pnt.h>
21 //==================================================================================================
22 ConstructionPlugin_Point::ConstructionPlugin_Point()
26 //==================================================================================================
27 const std::string& ConstructionPlugin_Point::getKind()
29 static std::string MY_KIND = ConstructionPlugin_Point::ID();
33 //==================================================================================================
34 void ConstructionPlugin_Point::initAttributes()
36 data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId());
37 data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId());
38 data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId());
40 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
42 data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
43 data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId());
44 data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId());
45 data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
48 //==================================================================================================
49 void ConstructionPlugin_Point::execute()
53 std::string aCreationMethod = string(CREATION_METHOD())->value();
54 if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
55 aShape = createByXYZ();
56 } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
57 aShape = createByDistanceOnEdge();
61 std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
62 aConstr->setShape(aShape);
67 //==================================================================================================
68 bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
70 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
72 bool isCustomized = theDefaultPrs.get() != NULL &&
73 theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
74 //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
78 //==================================================================================================
79 GeomShapePtr ConstructionPlugin_Point::createByXYZ()
81 return GeomAlgoAPI_PointBuilder::point(real(X())->value(),
86 //==================================================================================================
87 GeomShapePtr ConstructionPlugin_Point::createByDistanceOnEdge()
90 AttributeSelectionPtr anEdgeSelection = selection(EDGE());
91 GeomShapePtr aShape = anEdgeSelection->value();
93 aShape = anEdgeSelection->context()->shape();
95 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
97 // Get distance value and percent flag.
98 double aValue = real(DISTANCE_VALUE())->value();
99 bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
102 bool anIsReverse = boolean(REVERSE())->value();
104 return GeomAlgoAPI_ShapeTools::findVertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);