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 <Graphic3d_AspectMarker3d.hxx>
16 #include <Prs3d_PointAspect.hxx>
17 #include <Prs3d_Root.hxx>
18 #include <gp_Pnt2d.hxx>
19 #include <Image_AlienPixMap.hxx>
20 #include <Graphic3d_MarkerImage.hxx>
21 #include <SelectMgr_EntityOwner.hxx>
22 #include <Select3D_SensitivePoint.hxx>
23 #include <SelectMgr_Selection.hxx>
24 #include <Select3D_SensitiveSegment.hxx>
26 extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
27 const std::string& theAttribute);
36 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Parallel, AIS_InteractiveObject);
37 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Parallel, AIS_InteractiveObject);
39 static Handle(Image_AlienPixMap) MyPixMap;
41 SketcherPrs_Parallel::SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint,
42 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
43 : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
45 if (MyPixMap.IsNull()) {
46 TCollection_AsciiString aFile(getenv("NewGeomResources"));
48 aFile += "parallel.png";
49 MyPixMap = new Image_AlienPixMap();
50 if (!MyPixMap->Load(aFile))
53 if (!MyPixMap.IsNull()) {
54 myAspect = new Graphic3d_AspectMarker3d(MyPixMap);
55 myPntArray = new Graphic3d_ArrayOfPoints(2);
56 myPntArray->AddVertex(0., 0., 0.);
57 myPntArray->AddVertex(0. ,0., 0.);
61 void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
62 const Handle(Prs3d_Presentation)& thePresentation,
63 const Standard_Integer theMode)
65 if (myAspect.IsNull())
68 std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
69 if (aLine1.get() == NULL)
72 std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
73 if (aLine2.get() == NULL)
76 std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine1->firstPoint();
77 std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLine1->lastPoint();
78 gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2.,
79 (aPnt1->y() + aPnt2->y())/2.,
80 (aPnt1->z() + aPnt2->z())/2.);
82 gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
83 gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
86 aP1.Translate(aShift);
88 aPnt1 = aLine2->firstPoint();
89 aPnt2 = aLine2->lastPoint();
90 gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2.,
91 (aPnt1->y() + aPnt2->y())/2.,
92 (aPnt1->z() + aPnt2->z())/2.);
94 gp_Vec aVec2(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
95 aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
98 aP2.Translate(aShift);
100 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
101 aGroup->SetPrimitivesAspect(myAspect);
102 myPntArray->SetVertice(1, aP1);
103 myPntArray->SetVertice(2, aP2);
104 aGroup->AddPrimitiveArray(myPntArray);
107 void SketcherPrs_Parallel::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
108 const Standard_Integer aMode)
110 std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
111 if (aLine1.get() == NULL)
114 std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
115 if (aLine2.get() == NULL)
118 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
119 Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(eown, myPntArray->Vertice(1));
120 Handle(Select3D_SensitivePoint) aSP2 = new Select3D_SensitivePoint(eown, myPntArray->Vertice(2));
121 aSelection->Add(aSP1);
122 aSelection->Add(aSP2);