1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "SketcherPrs_Rigid.h"
22 #include "SketcherPrs_Tools.h"
23 #include "SketcherPrs_PositionMgr.h"
25 #include <GeomAPI_Pnt.h>
26 #include <GeomAPI_Edge.h>
27 #include <GeomAPI_Curve.h>
28 #include <GeomAPI_Vertex.h>
30 #include <ModelAPI_AttributeRefAttr.h>
32 #include <SketchPlugin_Constraint.h>
34 #include <gp_Pnt2d.hxx>
36 #include <Graphic3d_AspectLine3d.hxx>
37 #include <Prs3d_Root.hxx>
39 #include <GeomAdaptor_Curve.hxx>
40 #include <BRep_Tool.hxx>
41 #include <StdPrs_DeflectionCurve.hxx>
42 #include <StdPrs_Point.hxx>
43 #include <Geom_CartesianPoint.hxx>
47 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
49 static Handle(Image_AlienPixMap) MyPixMap;
53 SketcherPrs_Rigid::SketcherPrs_Rigid(ModelAPI_Feature* theConstraint,
54 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
55 : SketcherPrs_SymbolPrs(theConstraint, thePlane)
59 bool SketcherPrs_Rigid::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
60 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
62 bool aReadyToDisplay = false;
64 std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
65 std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
66 aData->refattr(SketchPlugin_Constraint::ENTITY_A());
67 AttributePtr aRefAttr = anAttr->attr();
68 if (anAttr->isObject()) {
69 // The constraint attached to an object
70 ObjectPtr aObj = anAttr->object();
71 aReadyToDisplay = SketcherPrs_Tools::getShape(aObj).get() != NULL;
74 // The constraint attached to a point
75 std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
76 SketchPlugin_Constraint::ENTITY_A());
77 aReadyToDisplay = aPnt.get() != NULL;
79 return aReadyToDisplay;
82 bool SketcherPrs_Rigid::updateIfReadyToDisplay(double theStep, bool withColor) const
84 if (!IsReadyToDisplay(myConstraint, myPlane))
87 myPntArray = new Graphic3d_ArrayOfPoints(1, withColor);
88 std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
89 std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
90 aData->refattr(SketchPlugin_Constraint::ENTITY_A());
91 AttributePtr aRefAttr = anAttr->attr();
92 if (anAttr->isObject()) {
93 // The constraint attached to an object
94 ObjectPtr aObj = anAttr->object();
96 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
97 gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep);
98 myPntArray->AddVertex(aP1);
100 // The constraint attached to a point
101 std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint,
102 SketchPlugin_Constraint::ENTITY_A());
103 std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y() + theStep);
104 myPntArray->AddVertex(aPoint->impl<gp_Pnt>());
110 void SketcherPrs_Rigid::drawLines(const Handle(Prs3d_Presentation)& thePrs,
111 Quantity_Color theColor) const
113 ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
114 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
115 std::shared_ptr<GeomAPI_Shape> aShape;
116 if (aFeature.get()) {
117 // If constraint attached to a feature
118 const std::list<ResultPtr>& aResults = aFeature->results();
119 std::list<ResultPtr>::const_iterator aIt;
121 for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
122 aShape = (*aIt)->shape();
123 if (aShape->isEdge())
127 // Else it is a result
128 aShape = SketcherPrs_Tools::getShape(aObj);
130 if (aShape.get() == NULL)
133 Handle(Prs3d_PointAspect) aPntAspect = new Prs3d_PointAspect(Aspect_TOM_PLUS, theColor, 1);
134 myDrawer->SetPointAspect(aPntAspect);
135 drawShape(aShape, thePrs, theColor);