]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_Parallel.cpp
Salome HOME
ed23fc51922f32a97c2606023c3ec33244e517b7
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Parallel.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Parallel.cpp
4 // Created:     16 February 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Parallel.h"
8 #include "SketcherPrs_Tools.h"
9
10 #include <GeomAPI_Pnt.h>
11
12 #include <SketchPlugin_Constraint.h>
13
14 #include <AIS_Drawer.hxx>
15 #include <gp_Pnt2d.hxx>
16 #include <Image_AlienPixMap.hxx>
17
18 #include <Prs3d_PointAspect.hxx>
19 #include <Prs3d_Root.hxx>
20 #include <Prs3d_LineAspect.hxx>
21
22 #include <Graphic3d_MarkerImage.hxx>
23 #include <Graphic3d_AspectMarker3d.hxx>
24 #include <Graphic3d_AspectLine3d.hxx>
25 #include <Graphic3d_ArrayOfSegments.hxx>
26
27 #include <Select3D_SensitivePoint.hxx>
28 #include <Select3D_SensitiveSegment.hxx>
29
30 #include <SelectMgr_SequenceOfOwner.hxx>
31 #include <SelectMgr_Selection.hxx>
32 #include <SelectMgr_EntityOwner.hxx>
33
34
35 extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
36                                                       const std::string& theAttribute);
37
38 #ifdef WIN32
39 # define FSEP "\\"
40 #else
41 # define FSEP "/"
42 #endif
43
44
45 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Parallel, AIS_InteractiveObject);
46 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Parallel, AIS_InteractiveObject);
47
48 static Handle(Image_AlienPixMap) MyPixMap;
49
50 SketcherPrs_Parallel::SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint, 
51                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
52  : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
53 {
54   if (MyPixMap.IsNull()) {
55     TCollection_AsciiString aFile(getenv("NewGeomResources"));
56     aFile += FSEP;
57     aFile += "parallel.png";
58     MyPixMap = new Image_AlienPixMap();
59     if (!MyPixMap->Load(aFile))
60       MyPixMap.Nullify();
61   }
62   if (!MyPixMap.IsNull()) {
63     myAspect = new Graphic3d_AspectMarker3d(MyPixMap);
64     myPntArray = new Graphic3d_ArrayOfPoints(2);
65     myPntArray->AddVertex(0., 0., 0.);
66     myPntArray->AddVertex(0. ,0., 0.);
67   }
68   SetAutoHilight(Standard_False);
69 }  
70
71 void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
72                                    const Handle(Prs3d_Presentation)& thePresentation, 
73                                    const Standard_Integer theMode)
74 {
75   if (myAspect.IsNull())
76     return;
77
78   std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
79   if (aLine1.get() == NULL)
80     return;
81
82   std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
83   if (aLine2.get() == NULL)
84     return;
85
86   std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine1->firstPoint();
87   std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLine1->lastPoint();
88   gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2.,
89              (aPnt1->y() + aPnt2->y())/2.,
90              (aPnt1->z() + aPnt2->z())/2.);
91
92   gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
93   gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
94   aShift.Normalize();
95   aShift.Multiply(20);
96   aP1.Translate(aShift);
97
98   aPnt1 = aLine2->firstPoint();
99   aPnt2 = aLine2->lastPoint();
100   gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2.,
101              (aPnt1->y() + aPnt2->y())/2.,
102              (aPnt1->z() + aPnt2->z())/2.);
103
104   gp_Vec aVec2(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
105   aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
106   aShift.Normalize();
107   aShift.Multiply(20);
108   aP2.Translate(aShift);
109
110   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
111   aGroup->SetPrimitivesAspect(myAspect);
112   myPntArray->SetVertice(1, aP1);
113   myPntArray->SetVertice(2, aP2);
114   aGroup->AddPrimitiveArray(myPntArray);
115 }
116
117 void SketcherPrs_Parallel::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
118                                             const Standard_Integer aMode)
119 {
120   ClearSelected();
121   std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
122   if (aLine1.get() == NULL)
123     return;
124
125   std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
126   if (aLine2.get() == NULL)
127     return;
128
129   Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this);
130   Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(1));
131   Handle(Select3D_SensitivePoint) aSP2 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(2));
132   aSelection->Add(aSP1);
133   aSelection->Add(aSP2);
134 }
135
136 void SketcherPrs_Parallel::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, 
137                                            const SelectMgr_SequenceOfOwner& theOwners)
138 {
139
140   Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
141   aSelectionPrs->Clear();
142   drawLines(aSelectionPrs, Quantity_NOC_WHITE);
143
144   aSelectionPrs->SetDisplayPriority(9);
145   aSelectionPrs->Display();
146   thePM->Highlight(this);
147 }
148
149 void SketcherPrs_Parallel::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, 
150                                                  const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner)
151 {
152   thePM->Color(this, theColor);
153
154   Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
155   aHilightPrs->Clear();
156   drawLines(aHilightPrs, theColor);
157
158   if (thePM->IsImmediateModeOn())
159     thePM->AddToImmediateList(aHilightPrs);
160 }
161
162
163 void SketcherPrs_Parallel::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
164 {
165   std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
166   if (aLine1.get() == NULL)
167     return;
168
169   std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
170   if (aLine2.get() == NULL)
171     return;
172
173   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
174
175   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
176   aGroup->SetPrimitivesAspect(aLineAspect);
177
178   std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine1->firstPoint();
179   std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLine1->lastPoint();
180   Handle(Graphic3d_ArrayOfSegments) aLines = new Graphic3d_ArrayOfSegments(2, 1);
181   aLines->AddVertex(aPnt1->impl<gp_Pnt>());
182   aLines->AddVertex(aPnt2->impl<gp_Pnt>());
183   aGroup->AddPrimitiveArray(aLines);
184
185   aPnt1 = aLine2->firstPoint();
186   aPnt2 = aLine2->lastPoint();
187   aLines = new Graphic3d_ArrayOfSegments(2, 1);
188   aLines->AddVertex(aPnt1->impl<gp_Pnt>());
189   aLines->AddVertex(aPnt2->impl<gp_Pnt>());
190   aGroup->AddPrimitiveArray(aLines);
191 }
192
193 void SketcherPrs_Parallel::ClearSelected()
194 {
195   Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( NULL );  
196   if( !aSelectionPrs.IsNull() ) {
197     aSelectionPrs->Clear(); 
198   }
199 }