]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_Offset.cpp
Salome HOME
Issue #3231: Provide presentation for offset operation
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Offset.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "SketcherPrs_Offset.h"
21 #include "SketcherPrs_Tools.h"
22 #include "SketcherPrs_PositionMgr.h"
23
24 #include <SketchPlugin_Offset.h>
25
26 #include <ModelAPI_AttributeRefList.h>
27 #include <ModelAPI_AttributeDouble.h>
28
29 #include <Graphic3d_AspectLine3d.hxx>
30 #include <Prs3d_Root.hxx>
31
32
33 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Offset, SketcherPrs_SymbolPrs);
34
35 static Handle(Image_AlienPixMap) MyPixMap;
36
37 SketcherPrs_Offset::SketcherPrs_Offset(ModelAPI_Feature* theConstraint,
38   SketchPlugin_Sketch* theSketcher)
39   : SketcherPrs_SymbolPrs(theConstraint, theSketcher)
40 {
41 }
42
43 bool SketcherPrs_Offset::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
44   const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
45 {
46   bool aReadyToDisplay = false;
47
48   AttributeDoublePtr aValueAttr = theConstraint->real(SketchPlugin_Offset::VALUE_ID());
49   if (aValueAttr->isInitialized()) {
50     AttributeRefListPtr aSelectedEdges = theConstraint->reflist(SketchPlugin_Offset::EDGES_ID());
51     aReadyToDisplay = (aSelectedEdges->list().size() > 0);
52   }
53   return aReadyToDisplay;
54 }
55
56 bool SketcherPrs_Offset::updateIfReadyToDisplay(double theStep, bool withColor) const
57 {
58   if (!IsReadyToDisplay(myConstraint, plane()))
59     return false;
60   if (!plane())
61     return false;
62
63   // Set points of the presentation
64   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
65
66   AttributeRefListPtr aSelectedEdges = myConstraint->reflist(SketchPlugin_Offset::EDGES_ID());
67   int aNb = aSelectedEdges->size();
68
69   //std::list<std::shared_ptr<ModelAPI_Result> > aResList = myConstraint->results();
70   //int aRNb = aResList.size();
71
72   myPntArray = new Graphic3d_ArrayOfPoints(aNb, withColor);
73   int i;
74   ObjectPtr aObj;
75   gp_Pnt aP1;
76   // get position for each source object
77   for (i = 0; i < aNb; i++) {
78     aObj = aSelectedEdges->object(i);
79     if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
80       continue;
81     aP1 = aMgr->getPosition(aObj, this, theStep);
82     myPntArray->SetVertice(i + 1, aP1);
83   }
84   return true;
85 }
86
87 void SketcherPrs_Offset::drawLines(const Handle(Prs3d_Presentation)& thePrs,
88   Quantity_Color theColor) const
89 {
90   AttributeRefListPtr aSelectedEdges = myConstraint->reflist(SketchPlugin_Offset::EDGES_ID());
91   if (aSelectedEdges.get() == NULL)
92     return;
93
94   int aNb = aSelectedEdges->size();
95   if (aNb == 0)
96     return;
97
98   // Draw source objects
99   drawListOfShapes(aSelectedEdges, thePrs, theColor);
100 }