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>
17 #include <GeomAPI_Edge.h>
18 #include <GeomAPI_Pnt.h>
19 #include <GeomAPI_Vertex.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());
47 data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
48 data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
51 //==================================================================================================
52 void ConstructionPlugin_Point::execute()
56 std::string aCreationMethod = string(CREATION_METHOD())->value();
57 if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
58 aShape = createByXYZ();
59 } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
60 aShape = createByDistanceOnEdge();
61 } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
62 aShape = createByProjection();
66 std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
67 aConstr->setShape(aShape);
72 //==================================================================================================
73 bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
75 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
77 bool isCustomized = theDefaultPrs.get() != NULL &&
78 theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
79 //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
83 //==================================================================================================
84 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
86 return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(),
91 //==================================================================================================
92 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge()
95 AttributeSelectionPtr anEdgeSelection = selection(EDGE());
96 GeomShapePtr aShape = anEdgeSelection->value();
98 aShape = anEdgeSelection->context()->shape();
100 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
102 // Get distance value and percent flag.
103 double aValue = real(DISTANCE_VALUE())->value();
104 bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
107 bool anIsReverse = boolean(REVERSE())->value();
109 return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
112 //==================================================================================================
113 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjection()
116 AttributeSelectionPtr aPointSelection = selection(POINT());
117 GeomShapePtr aPointShape = aPointSelection->value();
118 if(!aPointShape.get()) {
119 aPointShape = aPointSelection->context()->shape();
121 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
124 AttributeSelectionPtr aPlaneSelection = selection(PLANE());
125 GeomShapePtr aPlaneShape = aPlaneSelection->value();
126 if(!aPlaneShape.get()) {
127 aPlaneShape = aPlaneSelection->context()->shape();
129 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
131 return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace);