Salome HOME
updated copyright message
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Offset.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
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::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);
55     }
56   }
57   return aReadyToDisplay;
58 }
59
60 bool SketcherPrs_Offset::updateIfReadyToDisplay(double theStep, bool withColor) const
61 {
62   if (!IsReadyToDisplay(myConstraint, plane()))
63     return false;
64   if (!plane())
65     return false;
66
67   // Set points of the presentation
68   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
69
70   AttributeRefListPtr aSelectedEdges = myConstraint->reflist(SketchPlugin_Offset::ENTITY_A());
71   int aNb = aSelectedEdges->size();
72
73   AttributeRefListPtr aOffcetEdges = myConstraint->reflist(SketchPlugin_Offset::ENTITY_B());
74   int aOffNb = aOffcetEdges->size();
75
76   myPntArray = new Graphic3d_ArrayOfPoints(aNb + aOffNb, withColor);
77   int i;
78   ObjectPtr aObj;
79   gp_Pnt aP1;
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)
84       continue;
85     aP1 = aMgr->getPosition(aObj, this, theStep);
86     myPntArray->SetVertice(i + 1, aP1);
87   }
88   for (i = aNb; i < aNb + aOffNb; i++) {
89     aObj = aOffcetEdges->object(i - aNb);
90     if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
91       continue;
92     aP1 = aMgr->getPosition(aObj, this, theStep);
93     myPntArray->SetVertice(i + 1, aP1);
94   }
95   return true;
96 }
97
98 void SketcherPrs_Offset::drawLines(const Handle(Prs3d_Presentation)& thePrs,
99   Quantity_Color theColor) const
100 {
101   AttributeRefListPtr aSelectedEdges = myConstraint->reflist(SketchPlugin_Offset::ENTITY_A());
102   if (aSelectedEdges.get() == NULL)
103     return;
104   AttributeRefListPtr aOffcetEdges = myConstraint->reflist(SketchPlugin_Offset::ENTITY_B());
105   if (aOffcetEdges.get() == NULL)
106     return;
107
108   if (aSelectedEdges->size() == 0)
109     return;
110
111   if (aOffcetEdges->size() == 0)
112     return;
113
114   // Draw source objects
115   drawListOfShapes(aSelectedEdges, thePrs, theColor);
116   // Draw offcet objects
117   drawListOfShapes(aOffcetEdges, thePrs, theColor);
118 }