1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "SketcherPrs_Offset.h"
21 #include "SketcherPrs_Tools.h"
22 #include "SketcherPrs_PositionMgr.h"
24 #include <SketchPlugin_Offset.h>
26 #include <ModelAPI_AttributeRefList.h>
27 #include <ModelAPI_AttributeDouble.h>
29 #include <Graphic3d_AspectLine3d.hxx>
30 #include <Prs3d_Root.hxx>
33 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Offset, SketcherPrs_SymbolPrs);
35 static Handle(Image_AlienPixMap) MyPixMap;
37 SketcherPrs_Offset::SketcherPrs_Offset(ModelAPI_Feature* theConstraint,
38 SketchPlugin_Sketch* theSketcher)
39 : SketcherPrs_SymbolPrs(theConstraint, theSketcher)
43 bool SketcherPrs_Offset::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
44 const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
46 bool aReadyToDisplay = false;
48 AttributeDoublePtr aValueAttr = theConstraint->real(SketchPlugin_Offset::VALUE_ID());
49 if (aValueAttr->isInitialized()) {
50 AttributeRefListPtr aSelectedEdges = theConstraint->reflist(SketchPlugin_Offset::ENTITY_A());
51 aReadyToDisplay = (aSelectedEdges->list().size() > 0);
52 if (aReadyToDisplay) {
53 AttributeRefListPtr aOffcetEdges = theConstraint->reflist(SketchPlugin_Offset::ENTITY_B());
54 aReadyToDisplay = (aOffcetEdges->list().size() > 0);
57 return aReadyToDisplay;
60 bool SketcherPrs_Offset::updateIfReadyToDisplay(double theStep, bool withColor) const
62 if (!IsReadyToDisplay(myConstraint, plane()))
67 // Set points of the presentation
68 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
70 AttributeRefListPtr aSelectedEdges = myConstraint->reflist(SketchPlugin_Offset::ENTITY_A());
71 int aNb = aSelectedEdges->size();
73 AttributeRefListPtr aOffcetEdges = myConstraint->reflist(SketchPlugin_Offset::ENTITY_B());
74 int aOffNb = aOffcetEdges->size();
76 myPntArray = new Graphic3d_ArrayOfPoints(aNb + aOffNb, withColor);
80 // get position for each source object
81 for (i = 0; i < aNb; i++) {
82 aObj = aSelectedEdges->object(i);
83 if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
85 aP1 = aMgr->getPosition(aObj, this, theStep);
86 myPntArray->SetVertice(i + 1, aP1);
88 for (i = aNb; i < aNb + aOffNb; i++) {
89 aObj = aOffcetEdges->object(i - aNb);
90 if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
92 aP1 = aMgr->getPosition(aObj, this, theStep);
93 myPntArray->SetVertice(i + 1, aP1);
98 void SketcherPrs_Offset::drawLines(const Handle(Prs3d_Presentation)& thePrs,
99 Quantity_Color theColor) const
101 AttributeRefListPtr aSelectedEdges = myConstraint->reflist(SketchPlugin_Offset::ENTITY_A());
102 if (aSelectedEdges.get() == NULL)
104 AttributeRefListPtr aOffcetEdges = myConstraint->reflist(SketchPlugin_Offset::ENTITY_B());
105 if (aOffcetEdges.get() == NULL)
108 if (aSelectedEdges->size() == 0)
111 if (aOffcetEdges->size() == 0)
114 // Draw source objects
115 drawListOfShapes(aSelectedEdges, thePrs, theColor);
116 // Draw offcet objects
117 drawListOfShapes(aOffcetEdges, thePrs, theColor);