1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_Parallel.cpp
4 // Created: 16 February 2015
5 // Author: Vitaly SMETANNIKOV
7 #include "SketcherPrs_Parallel.h"
8 #include "SketcherPrs_Tools.h"
10 #include <GeomAPI_Pnt.h>
12 #include <SketchPlugin_Constraint.h>
14 #include <AIS_Drawer.hxx>
15 #include <gp_Pnt2d.hxx>
16 #include <Image_AlienPixMap.hxx>
18 #include <Prs3d_PointAspect.hxx>
19 #include <Prs3d_Root.hxx>
20 #include <Prs3d_LineAspect.hxx>
22 #include <Graphic3d_MarkerImage.hxx>
23 #include <Graphic3d_AspectMarker3d.hxx>
24 #include <Graphic3d_AspectLine3d.hxx>
25 #include <Graphic3d_ArrayOfSegments.hxx>
27 #include <Select3D_SensitivePoint.hxx>
28 #include <Select3D_SensitiveSegment.hxx>
30 #include <SelectMgr_SequenceOfOwner.hxx>
31 #include <SelectMgr_Selection.hxx>
32 #include <SelectMgr_EntityOwner.hxx>
35 extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
36 const std::string& theAttribute);
45 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Parallel, AIS_InteractiveObject);
46 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Parallel, AIS_InteractiveObject);
48 static Handle(Image_AlienPixMap) MyPixMap;
50 SketcherPrs_Parallel::SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint,
51 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
52 : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
54 if (MyPixMap.IsNull()) {
55 TCollection_AsciiString aFile(getenv("NewGeomResources"));
57 aFile += "parallel.png";
58 MyPixMap = new Image_AlienPixMap();
59 if (!MyPixMap->Load(aFile))
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.);
68 SetAutoHilight(Standard_False);
71 void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
72 const Handle(Prs3d_Presentation)& thePresentation,
73 const Standard_Integer theMode)
75 if (myAspect.IsNull())
78 std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
79 if (aLine1.get() == NULL)
82 std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
83 if (aLine2.get() == NULL)
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.);
92 gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
93 gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
96 aP1.Translate(aShift);
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.);
104 gp_Vec aVec2(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
105 aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
108 aP2.Translate(aShift);
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);
117 void SketcherPrs_Parallel::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
118 const Standard_Integer aMode)
121 std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
122 if (aLine1.get() == NULL)
125 std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
126 if (aLine2.get() == NULL)
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);
136 void SketcherPrs_Parallel::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
137 const SelectMgr_SequenceOfOwner& theOwners)
140 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
141 aSelectionPrs->Clear();
142 drawLines(aSelectionPrs, Quantity_NOC_WHITE);
144 aSelectionPrs->SetDisplayPriority(9);
145 aSelectionPrs->Display();
146 thePM->Highlight(this);
149 void SketcherPrs_Parallel::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
150 const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner)
152 thePM->Color(this, theColor);
154 Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
155 aHilightPrs->Clear();
156 drawLines(aHilightPrs, theColor);
158 if (thePM->IsImmediateModeOn())
159 thePM->AddToImmediateList(aHilightPrs);
163 void SketcherPrs_Parallel::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
165 std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
166 if (aLine1.get() == NULL)
169 std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
170 if (aLine2.get() == NULL)
173 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
175 Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
176 aGroup->SetPrimitivesAspect(aLineAspect);
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);
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);
193 void SketcherPrs_Parallel::ClearSelected()
195 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( NULL );
196 if( !aSelectionPrs.IsNull() ) {
197 aSelectionPrs->Clear();