]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_Perpendicular.cpp
Salome HOME
Perpendicular constraint presentation created
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Perpendicular.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Perpendicular.cpp
4 // Created:     12 March 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Perpendicular.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 // Function which is defined in SketchPlugin_ConstraintDistance.cpp
35 extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
36                                                       const std::string& theAttribute);
37
38
39
40 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Perpendicular, SketcherPrs_SymbolPrs);
41 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Perpendicular, SketcherPrs_SymbolPrs);
42
43 static Handle(Image_AlienPixMap) MyPixMap;
44
45 SketcherPrs_Perpendicular::SketcherPrs_Perpendicular(SketchPlugin_Constraint* theConstraint, 
46                                                      const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
47  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
48 {
49   myPntArray = new Graphic3d_ArrayOfPoints(2);
50   myPntArray->AddVertex(0., 0., 0.);
51   myPntArray->AddVertex(0. ,0., 0.);
52 }  
53
54 void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
55                                    const Handle(Prs3d_Presentation)& thePresentation, 
56                                    const Standard_Integer theMode)
57 {
58   prepareAspect();
59
60   std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
61   if (aLine1.get() == NULL)
62     return;
63
64   std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
65   if (aLine2.get() == NULL)
66     return;
67
68   std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine1->firstPoint();
69   std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLine1->lastPoint();
70   gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2.,
71              (aPnt1->y() + aPnt2->y())/2.,
72              (aPnt1->z() + aPnt2->z())/2.);
73
74   gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
75   gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
76   aShift.Normalize();
77   aShift.Multiply(20);
78   aP1.Translate(aShift);
79
80   aPnt1 = aLine2->firstPoint();
81   aPnt2 = aLine2->lastPoint();
82   gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2.,
83              (aPnt1->y() + aPnt2->y())/2.,
84              (aPnt1->z() + aPnt2->z())/2.);
85
86   gp_Vec aVec2(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
87   aShift = aVec2.Crossed(myPlane->norm()->impl<gp_Dir>());
88   aShift.Normalize();
89   aShift.Multiply(20);
90   aP2.Translate(aShift);
91
92   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
93   aGroup->SetPrimitivesAspect(myAspect);
94   myPntArray->SetVertice(1, aP1);
95   myPntArray->SetVertice(2, aP2);
96   aGroup->AddPrimitiveArray(myPntArray);
97 }
98
99 void SketcherPrs_Perpendicular::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
100                                             const Standard_Integer aMode)
101 {
102   ClearSelected();
103
104   Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this);
105   Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(1));
106   Handle(Select3D_SensitivePoint) aSP2 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(2));
107   aSelection->Add(aSP1);
108   aSelection->Add(aSP2);
109 }
110
111 void SketcherPrs_Perpendicular::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, 
112                                            const SelectMgr_SequenceOfOwner& theOwners)
113 {
114
115   Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
116   aSelectionPrs->Clear();
117   drawLines(aSelectionPrs, Quantity_NOC_WHITE);
118
119   aSelectionPrs->SetDisplayPriority(9);
120   aSelectionPrs->Display();
121   thePM->Highlight(this);
122 }
123
124 void SketcherPrs_Perpendicular::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, 
125                                                  const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner)
126 {
127   thePM->Color(this, theColor);
128
129   Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
130   aHilightPrs->Clear();
131   drawLines(aHilightPrs, theColor);
132
133   if (thePM->IsImmediateModeOn())
134     thePM->AddToImmediateList(aHilightPrs);
135 }
136
137
138 void SketcherPrs_Perpendicular::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
139 {
140   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
141
142   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
143   aGroup->SetPrimitivesAspect(aLineAspect);
144
145   addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
146   addLine(aGroup, SketchPlugin_Constraint::ENTITY_B());
147 }
148