]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_Angle.cpp
Salome HOME
Special symbol for Angle/Radius. For consistency it sets the empty special symbol...
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Angle.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Angle.cpp
4 // Created:     20 August 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Angle.h"
8 #include "SketcherPrs_Tools.h"
9
10 #include <SketchPlugin_ConstraintAngle.h>
11 #include <SketchPlugin_Constraint.h>
12
13 #include <GeomAPI_Edge.h>
14 #include <GeomAPI_Lin.h>
15 #include <GeomDataAPI_Point2D.h>
16
17 #include <ModelAPI_AttributeRefAttr.h>
18 #include <ModelAPI_AttributeDouble.h>
19
20 #include <TopExp.hxx>
21 #include <BRep_Tool.hxx>
22
23 #define PI 3.1415926535897932
24
25 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension);
26 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Angle, AIS_AngleDimension);
27
28
29 static const Standard_ExtCharacter MyEmptySymbol(' ');
30 static const Standard_ExtCharacter MySummSymbol(0x03A3);
31
32 SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint, 
33                                      const std::shared_ptr<GeomAPI_Ax3>& thePlane)
34 : AIS_AngleDimension(gp_Pnt(0,0,0), gp_Pnt(1,0,0), gp_Pnt(0,1,0)), myConstraint(theConstraint), myPlane(thePlane)
35 {
36   myAspect = new Prs3d_DimensionAspect();
37   myAspect->MakeArrows3d(false);
38   myAspect->MakeText3d(false);
39   myAspect->MakeTextShaded(false);
40   myAspect->MakeUnitsDisplayed(false);
41   myAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getDefaultTextHeight());
42   myAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize());
43   
44   SetDimensionAspect(myAspect);
45   SetSelToleranceForText2d(SketcherPrs_Tools::getDefaultTextHeight());
46 }
47
48 void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
49                                 const Handle(Prs3d_Presentation)& thePresentation, 
50                                 const Standard_Integer theMode)
51 {
52   DataPtr aData = myConstraint->data();
53
54   // Flyout point
55   std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = 
56     std::dynamic_pointer_cast<GeomDataAPI_Point2D>
57     (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
58   if (!aFlyoutAttr->isInitialized())
59     return; // can not create a good presentation
60
61   std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = myPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
62
63   AttributeRefAttrPtr anAttr1 = aData->refattr(SketchPlugin_Constraint::ENTITY_A());
64   if (!anAttr1->isInitialized())
65     return;
66
67   AttributeRefAttrPtr anAttr2 = aData->refattr(SketchPlugin_Constraint::ENTITY_B());
68   if (!anAttr2->isInitialized())
69     return;
70
71   // Get angle edges
72   ObjectPtr aObj1 = anAttr1->object();
73   ObjectPtr aObj2 = anAttr2->object();
74
75   std::shared_ptr<GeomAPI_Shape> aShape1 = SketcherPrs_Tools::getShape(aObj1);
76   std::shared_ptr<GeomAPI_Shape> aShape2 = SketcherPrs_Tools::getShape(aObj2);
77
78   if (!aShape1 && !aShape2)
79     return;
80
81   TopoDS_Shape aTEdge1 = aShape1->impl<TopoDS_Shape>();
82   TopoDS_Shape aTEdge2 = aShape2->impl<TopoDS_Shape>();
83
84   TopoDS_Edge aEdge1 = TopoDS::Edge(aTEdge1);
85   TopoDS_Edge aEdge2 = TopoDS::Edge(aTEdge2);
86   SetMeasuredGeometry(aEdge1, aEdge2);
87
88   const gp_Pnt& aCenter = CenterPoint();
89   const gp_Pnt& aFirst = FirstPoint();
90   const gp_Pnt& aSecond = SecondPoint();
91
92   gp_Dir aBisector((aFirst.XYZ() + aSecond.XYZ()) * 0.5 - aCenter.XYZ());
93
94   gp_Pnt aFlyPnt(aFlyoutPnt->x(), aFlyoutPnt->y(), aFlyoutPnt->z());
95   gp_XYZ aFlyDir = aFlyPnt.XYZ() - aCenter.XYZ();
96   double aDist = aFlyDir.Dot(aBisector.XYZ());
97   SetFlyout(aDist);
98
99   // Angle value is in degrees
100   AttributeDoublePtr aVal = aData->real(SketchPlugin_Constraint::VALUE());
101   SetCustomValue(aVal->value() * PI / 180.0);
102
103   myAspect->SetExtensionSize(myAspect->ArrowAspect()->Length());
104   myAspect->SetArrowTailSize(myAspect->ArrowAspect()->Length());
105
106   AttributeDoublePtr aValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE());
107   std::set<std::string> aParams = aValue->usedParameters();
108   if (aParams.size() > 0) {
109     SetSpecialSymbol(MySummSymbol);
110     SetDisplaySpecialSymbol(AIS_DSS_Before);
111   }
112   else {
113     SetSpecialSymbol(MyEmptySymbol);
114     SetDisplaySpecialSymbol(AIS_DSS_Before);
115   }
116
117   AIS_AngleDimension::Compute(thePresentationManager, thePresentation, theMode);
118 }
119
120 void SketcherPrs_Angle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
121                                                    const Standard_Integer theMode)
122 {
123   Standard_Integer aMode;
124   switch (theMode) {
125   case 0: // we should use selection of all objects
126     aMode = 0;
127     break;
128   case SketcherPrs_Tools::Sel_Dimension_All:
129     aMode = 0;
130     break;
131   case SketcherPrs_Tools::Sel_Dimension_Line:
132     aMode = 1;
133     break;
134   case SketcherPrs_Tools::Sel_Dimension_Text:
135     aMode = 2;
136     break;
137   default: {
138     // there are own selection modes, so the others should be ignored
139     // otherwise, the text selection appears in the viewer
140     return; 
141   }
142   }
143   AIS_AngleDimension::ComputeSelection(aSelection, aMode);
144 }