Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
[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
17 #include <Prs3d_PointAspect.hxx>
18 #include <Prs3d_Root.hxx>
19 #include <Prs3d_LineAspect.hxx>
20
21 #include <Graphic3d_MarkerImage.hxx>
22 #include <Graphic3d_AspectMarker3d.hxx>
23 #include <Graphic3d_AspectLine3d.hxx>
24 #include <Graphic3d_ArrayOfSegments.hxx>
25
26 #include <Select3D_SensitivePoint.hxx>
27 #include <Select3D_SensitiveSegment.hxx>
28
29 #include <SelectMgr_SequenceOfOwner.hxx>
30 #include <SelectMgr_Selection.hxx>
31 #include <SelectMgr_EntityOwner.hxx>
32
33
34 extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
35                                                       const std::string& theAttribute);
36
37
38 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Parallel, SketcherPrs_SymbolPrs);
39 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Parallel, SketcherPrs_SymbolPrs);
40
41 static Handle(Image_AlienPixMap) MyPixMap;
42
43 SketcherPrs_Parallel::SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint, 
44                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
45  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
46 {
47   myPntArray = new Graphic3d_ArrayOfPoints(2);
48   myPntArray->AddVertex(0., 0., 0.);
49   myPntArray->AddVertex(0. ,0., 0.);
50 }  
51
52 void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
53                                    const Handle(Prs3d_Presentation)& thePresentation, 
54                                    const Standard_Integer theMode)
55 {
56   prepareAspect();
57
58   std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
59   if (aLine1.get() == NULL)
60     return;
61
62   std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
63   if (aLine2.get() == NULL)
64     return;
65
66   std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine1->firstPoint();
67   std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLine1->lastPoint();
68   gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2.,
69              (aPnt1->y() + aPnt2->y())/2.,
70              (aPnt1->z() + aPnt2->z())/2.);
71
72   gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
73   gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
74   aShift.Normalize();
75   aShift.Multiply(20);
76   aP1.Translate(aShift);
77
78   aPnt1 = aLine2->firstPoint();
79   aPnt2 = aLine2->lastPoint();
80   gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2.,
81              (aPnt1->y() + aPnt2->y())/2.,
82              (aPnt1->z() + aPnt2->z())/2.);
83
84   gp_Vec aVec2(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
85   aShift = aVec2.Crossed(myPlane->norm()->impl<gp_Dir>());
86   aShift.Normalize();
87   aShift.Multiply(20);
88   aP2.Translate(aShift);
89
90   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
91   aGroup->SetPrimitivesAspect(myAspect);
92   myPntArray->SetVertice(1, aP1);
93   myPntArray->SetVertice(2, aP2);
94   aGroup->AddPrimitiveArray(myPntArray);
95 }
96
97 void SketcherPrs_Parallel::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
98                                             const Standard_Integer aMode)
99 {
100   ClearSelected();
101
102   Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this);
103   Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(1));
104   Handle(Select3D_SensitivePoint) aSP2 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(2));
105   aSelection->Add(aSP1);
106   aSelection->Add(aSP2);
107 }
108
109 void SketcherPrs_Parallel::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, 
110                                            const SelectMgr_SequenceOfOwner& theOwners)
111 {
112
113   Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
114   aSelectionPrs->Clear();
115   drawLines(aSelectionPrs, Quantity_NOC_WHITE);
116
117   aSelectionPrs->SetDisplayPriority(9);
118   aSelectionPrs->Display();
119   thePM->Highlight(this);
120 }
121
122 void SketcherPrs_Parallel::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, 
123                                                  const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner)
124 {
125   thePM->Color(this, theColor);
126
127   Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
128   aHilightPrs->Clear();
129   drawLines(aHilightPrs, theColor);
130
131   if (thePM->IsImmediateModeOn())
132     thePM->AddToImmediateList(aHilightPrs);
133 }
134
135
136 void SketcherPrs_Parallel::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
137 {
138   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
139
140   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
141   aGroup->SetPrimitivesAspect(aLineAspect);
142
143   addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
144   addLine(aGroup, SketchPlugin_Constraint::ENTITY_B());
145 }
146