Salome HOME
Issue #901 - It is possible to define empty name for parameter
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Coincident.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Coincident.cpp
4 // Created:     12 February 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Coincident.h"
8 #include "SketcherPrs_Tools.h"
9
10 #include <ModelAPI_AttributeRefAttr.h>
11 #include <GeomDataAPI_Point2D.h>
12 #include <GeomDataAPI_Dir.h>
13 #include <GeomDataAPI_Point.h>
14
15 #include <GeomAPI_XYZ.h>
16 #include <GeomAPI_Dir.h>
17 #include <GeomAPI_Pnt2d.h>
18
19 #include <SketchPlugin_Constraint.h>
20
21 #include <Graphic3d_AspectMarker3d.hxx>
22 #include <Graphic3d_ArrayOfPoints.hxx>
23 #include <Prs3d_PointAspect.hxx>
24 #include <Prs3d_Root.hxx>
25 #include <SelectMgr_EntityOwner.hxx>
26 #include <SelectMgr_Selection.hxx>
27 #include <Select3D_SensitivePoint.hxx>
28
29
30 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject);
31 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
32
33 SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint, 
34                                                const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
35  : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
36 {
37   
38 }  
39
40
41
42 void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
43                                    const Handle(Prs3d_Presentation)& thePresentation, 
44                                    const Standard_Integer theMode)
45 {
46   std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint, 
47                                                                     SketchPlugin_Constraint::ENTITY_A());
48   if (aPnt.get() == NULL)
49     aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_B());
50   if (aPnt.get() == NULL)
51     return;
52
53   std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y());
54   myPoint = aPoint->impl<gp_Pnt>();
55
56   static Handle(Graphic3d_AspectMarker3d) aPtA;
57   if (aPtA.IsNull()) {
58     aPtA = new Graphic3d_AspectMarker3d ();
59   }
60   aPtA->SetType(Aspect_TOM_RING3);
61   aPtA->SetScale(2.);
62   aPtA->SetColor(Quantity_NOC_YELLOW);
63
64   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
65   aGroup->SetPrimitivesAspect(aPtA);
66   Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
67   aPntArray->AddVertex (aPoint->x(), aPoint->y(), aPoint->z());
68   aGroup->AddPrimitiveArray (aPntArray);
69
70   aPtA->SetType(Aspect_TOM_RING1);
71   aPtA->SetScale(1.);
72   aPtA->SetColor(Quantity_NOC_BLACK);
73   aGroup->SetPrimitivesAspect(aPtA);
74   aGroup->AddPrimitiveArray (aPntArray);
75
76   aPtA->SetType(Aspect_TOM_POINT);
77   aPtA->SetScale(5.);
78   aGroup->SetPrimitivesAspect(aPtA);
79   aGroup->AddPrimitiveArray (aPntArray);
80 }
81
82
83 void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
84                                             const Standard_Integer aMode)
85 {
86 //  if ((aMode == 0) || (aMode == SketcherPrs_Tools::Sel_Constraint)) {
87 //    Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this, 10);
88 //    Handle(Select3D_SensitivePoint) aSp = new Select3D_SensitivePoint(aOwn, myPoint);
89 //    aSelection->Add(aSp);
90 //  }
91 }
92
93 void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
94 {
95   SetColor(Quantity_Color(aCol));
96 }
97
98 void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol)
99 {
100   hasOwnColor=Standard_True;
101   myOwnColor=aCol;
102 }