3 #include "Sample2D_Face.h"
5 IMPLEMENT_STANDARD_HANDLE(Sample2D_Face,AIS2D_InteractiveObject)
6 IMPLEMENT_STANDARD_RTTIEXT(Sample2D_Face,AIS2D_InteractiveObject)
8 Sample2D_Face::Sample2D_Face (TopoDS_Face& aFace)
9 :AIS2D_InteractiveObject(),myFace(aFace)
15 myFORWARDColorIndex = 2;
16 myREVERSEDColorIndex = 3;
17 myINTERNALColorIndex = 4;
18 myEXTERNALColorIndex = 5;
24 #include "TopExp_Explorer.hxx"
25 #include "BRep_Tool.hxx"
27 #include "TopoDS_Edge.hxx"
29 #include "TopoDS_Vertex.hxx"
31 #include "Graphic2d_Marker.hxx"
32 #include "Graphic2d_PolylineMarker.hxx"
34 #include "Prs2d_AspectLine.hxx"
35 #include "Graphic2d_TypeOfPolygonFilling.hxx"
37 void Sample2D_Face::SetContext(const Handle(AIS2D_InteractiveContext)& theContext)
39 if(myFace.IsNull() || myFace.ShapeType()!=TopAbs_FACE) return;
41 AIS2D_InteractiveObject::SetContext(theContext);
43 Handle(Prs2d_AspectLine) aLineAspect_FORWARD = new Prs2d_AspectLine;
45 aLineAspect_FORWARD->SetTypeOfFill(Graphic2d_TOPF_EMPTY);
46 aLineAspect_FORWARD->SetTypeIndex(myTypeIndex);
47 aLineAspect_FORWARD->SetWidthIndex(myWidthIndex);
48 aLineAspect_FORWARD->SetColorIndex(myFORWARDColorIndex);
50 Handle(Prs2d_AspectLine) aLineAspect_REVERSED = new Prs2d_AspectLine;
51 aLineAspect_REVERSED->SetTypeOfFill(Graphic2d_TOPF_EMPTY);
52 aLineAspect_REVERSED->SetTypeIndex(myTypeIndex);
53 aLineAspect_REVERSED->SetWidthIndex(myWidthIndex);
54 aLineAspect_REVERSED->SetColorIndex(myREVERSEDColorIndex);
56 Handle(Prs2d_AspectLine) aLineAspect_INTERNAL = new Prs2d_AspectLine;
57 aLineAspect_INTERNAL->SetTypeOfFill(Graphic2d_TOPF_EMPTY);
58 aLineAspect_INTERNAL->SetTypeIndex(myTypeIndex);
59 aLineAspect_INTERNAL->SetWidthIndex(myWidthIndex);
60 aLineAspect_INTERNAL->SetColorIndex(myINTERNALColorIndex);
62 Handle(Prs2d_AspectLine) aLineAspect_EXTERNAL = new Prs2d_AspectLine;
63 aLineAspect_EXTERNAL->SetTypeOfFill(Graphic2d_TOPF_EMPTY);
64 aLineAspect_EXTERNAL->SetTypeIndex(myTypeIndex);
65 aLineAspect_EXTERNAL->SetWidthIndex(myWidthIndex);
66 aLineAspect_EXTERNAL->SetColorIndex(myEXTERNALColorIndex);
70 Handle(Graphic2d_SetOfCurves) segment_FORWARD;
71 segment_FORWARD = new Graphic2d_SetOfCurves(this);
73 Handle(Graphic2d_SetOfCurves) segment_REVERSED;
74 segment_REVERSED = new Graphic2d_SetOfCurves(this);
76 Handle(Graphic2d_SetOfCurves) segment_INTERNAL;
77 segment_INTERNAL = new Graphic2d_SetOfCurves(this);
79 Handle(Graphic2d_SetOfCurves) segment_EXTERNAL;
80 segment_EXTERNAL = new Graphic2d_SetOfCurves(this);
83 Standard_Integer i = 1;
84 myFace.Orientation(TopAbs_FORWARD);
85 TopExp_Explorer ex(myFace,TopAbs_EDGE);
87 const Handle(Geom2d_Curve) Curve = BRep_Tool::CurveOnSurface
88 (TopoDS::Edge(ex.Current()),TopoDS::Face(myFace),f,l);
90 Handle(Geom2d_TrimmedCurve) c = new Geom2d_TrimmedCurve(Curve,f,l);
94 // null curve --> EDGE have a null lenght
95 // --> get first and last Vertices
96 TopoDS_Edge CurrentEdge= TopoDS::Edge(ex.Current());
98 TopoDS_Vertex FirstVertex = TopExp::FirstVertex(CurrentEdge);
99 TopoDS_Vertex LastVertex = TopExp::LastVertex(CurrentEdge);
101 if (FirstVertex != LastVertex)
102 Standard_Failure::Raise("Null Edge pcurve But different vertices");
104 gp_Pnt aPnt = BRep_Tool::Pnt(FirstVertex);
107 Handle(Graphic2d_Marker) aMarker=
108 new Graphic2d_Marker(this,myMarkerIndex,
110 myMarkerWidth,myMarkerHeight,0);
112 switch (ex.Current().Orientation())
114 case TopAbs_FORWARD: aMarker->SetColorIndex (myFORWARDColorIndex); break;
115 case TopAbs_REVERSED: aMarker->SetColorIndex (myREVERSEDColorIndex); break;
116 case TopAbs_INTERNAL: aMarker->SetColorIndex (myINTERNALColorIndex); break;
117 case TopAbs_EXTERNAL: aMarker->SetColorIndex (myEXTERNALColorIndex); break;
127 Graphic2d_Array1OfVertex aListVertex(1,3);
128 if (v.Magnitude() > gp::Resolution()) {
132 p2.SetCoord(- L*d.X() - H*d.Y(),- L*d.Y() + H*d.X());
133 aListVertex(1)=Graphic2d_Vertex(p2.X(),p2.Y());
135 p2.SetCoord(- L*d.X() + H*d.Y(),- L*d.Y() - H*d.X());
136 aListVertex(2)=Graphic2d_Vertex(0.,0.);
137 aListVertex(3)=Graphic2d_Vertex(p2.X(),p2.Y());
140 Handle(Graphic2d_PolylineMarker) aMarker=
141 new Graphic2d_PolylineMarker(this,p1.X(),p1.Y(),aListVertex);
145 switch (ex.Current().Orientation())
147 case TopAbs_FORWARD: {
148 segment_FORWARD->Add(c);
149 SetAspect(aLineAspect_FORWARD, aMarker);
152 case TopAbs_REVERSED: {
153 segment_REVERSED->Add(c);
154 SetAspect(aLineAspect_REVERSED, aMarker);
157 case TopAbs_INTERNAL: {
158 segment_INTERNAL->Add(c);
159 SetAspect(aLineAspect_INTERNAL, aMarker);
162 case TopAbs_EXTERNAL: {
163 segment_EXTERNAL->Add(c);
164 SetAspect(aLineAspect_EXTERNAL, aMarker);
175 SetAspect(aLineAspect_FORWARD, segment_FORWARD);
176 SetAspect(aLineAspect_REVERSED, segment_REVERSED);
177 SetAspect(aLineAspect_INTERNAL, segment_INTERNAL);
178 SetAspect(aLineAspect_EXTERNAL, segment_EXTERNAL);