1 #include <AIS2D_InteractiveObject.ixx>
2 #include <Prs2d_AspectLine.hxx>
3 #include <Prs2d_Point.hxx>
4 #include <V2d_Viewer.hxx>
5 #include <AIS2D_ProjShape.hxx>
6 #include <AIS2D_PrimitiveArchit.hxx>
7 #include <Graphic2d_Segment.hxx>
8 #include <Graphic2d_InfiniteLine.hxx>
9 #include <Graphic2d_Polyline.hxx>
10 #include <Graphic2d_PolylineMarker.hxx>
11 #include <Graphic2d_Circle.hxx>
12 #include <Graphic2d_CircleMarker.hxx>
13 #include <Graphic2d_Ellips.hxx>
14 #include <Graphic2d_EllipsMarker.hxx>
15 #include <GGraphic2d_Curve.hxx>
18 #define NUM_ASPECTROOT 29
21 AIS2D_InteractiveObject::AIS2D_InteractiveObject()
23 : Graphic2d_GraphicObject(),
24 myDrawer( new Prs2d_Drawer() ),
25 myHighlightMode( AIS2D_TOD_PRIMITIVE ),
31 myDetectedPrimSeq( new AIS2D_HSequenceOfPrimArchit() ),
32 mySelectedPrimSeq( new AIS2D_HSequenceOfPrimArchit() )
35 AIS2D_DataMapOfPrimAspects theAspect(NUM_ASPECTROOT);
36 myAspects = theAspect;
37 printf(" $$$ Creates AIS2D_InteractiveObject()\n");
40 void AIS2D_InteractiveObject::SetAttributes( const Handle(Prs2d_Drawer)& aDrawer ) {
44 void AIS2D_InteractiveObject::UnsetAttributes() {
45 myDrawer = new Prs2d_Drawer();
48 void AIS2D_InteractiveObject::SetAspect( const Handle(Prs2d_AspectRoot)& anAspect ) {
50 if ( ! PrimitiveExist(anAspect->GetAspectName()) ) return;
52 switch ( anAspect->GetAspectName() ) {
56 if ( GetContext().IsNull() ) {
57 myDrawer->SetAspect( anAspect, Prs2d_AN_LINE );
60 Handle(Prs2d_AspectLine) theAspLine =
61 Handle(Prs2d_AspectLine)::DownCast( anAspect );
63 Quantity_Color aColor;
64 Aspect_TypeOfLine aType;
65 Aspect_WidthOfLine aWidth;
67 Quantity_Color aIntColor;
68 Graphic2d_TypeOfPolygonFilling aTypeFill;
69 Standard_Integer aTile;
70 Standard_Boolean aDrawEdge;
72 theAspLine->ValuesOfLine( aColor, aType, aWidth );
73 theAspLine->ValuesOfPoly( aIntColor, aTypeFill, aTile, aDrawEdge );
75 Standard_Integer colorInd = theAspLine->ColorIndex();
76 Standard_Integer typeInd = theAspLine->TypeIndex();
77 Standard_Integer widthInd = theAspLine->WidthIndex();
78 Standard_Integer colorIntInd = theAspLine->InterColorIndex();
81 colorInd = GetContext()->InitializeColor( aColor );
82 theAspLine->SetColorIndex( colorInd );
86 typeInd = GetContext()->InitializeStyle( aType );
87 theAspLine->SetTypeIndex( typeInd );
91 widthInd = GetContext()->InitializeWidth( aWidth );
92 theAspLine->SetWidthIndex( widthInd );
96 colorIntInd = GetContext()->InitializeColor( aIntColor );
97 theAspLine->SetIntColorInd( colorIntInd );
100 if ( this->IsKind(STANDARD_TYPE(AIS2D_ProjShape) ) ) {
102 Handle(AIS2D_ProjShape) thePS = Handle(AIS2D_ProjShape)::DownCast(this);
103 Handle(Graphic2d_Line) theLines = thePS->GetPrimitives();
104 theLines->SetColorIndex( colorInd );
105 theLines->SetTypeIndex( typeInd );
106 theLines->SetWidthIndex( widthInd );
108 if ( thePS->IsHLMode() ) {
109 Handle(Graphic2d_Line) theHLines = thePS->GetHLPrimitives();
110 theHLines->SetColorIndex( colorInd );
111 theHLines->SetWidthIndex( widthInd );
112 Standard_Integer theDashInd = GetContext()->InitializeStyle( Aspect_TOL_DASH );
113 theHLines->SetTypeIndex( theDashInd );
119 for ( Standard_Integer i = 1; i <= Length(); i++ ) {
121 if ( Primitive(i)->IsKind(STANDARD_TYPE(Graphic2d_Line)) ) {
123 Handle(Graphic2d_Line) theLine =
124 Handle(Graphic2d_Line)::DownCast( Primitive(i) );
126 theLine->SetColorIndex( colorInd );
127 theLine->SetTypeIndex( typeInd );
128 theLine->SetWidthIndex( widthInd );
130 theLine->SetInteriorColorIndex( colorIntInd );
131 theLine->SetTypeOfPolygonFilling( aTypeFill );
132 theLine->SetInteriorPattern( aTile );
133 theLine->SetDrawEdge( aDrawEdge );
135 if ( !myAspects.IsBound(theLine) )
136 myAspects.Bind( theLine, theAspLine );
138 myAspects( theLine ) = theAspLine;
140 } // end if STANDARD_TYPE is Graphic2d_Line
146 } // end case Prs2d_AN_LINE
148 case Prs2d_AN_HIDDENLINE: {
150 case Prs2d_AN_TEXT: {
152 case Prs2d_AN_HIDINGPOLY: {
154 case Prs2d_AN_HIDINGTEXT: {
156 case Prs2d_AN_FRAMEDTEXT: {
158 case Prs2d_AN_LAST: {
160 case Prs2d_AN_UNKNOWN: {
163 myDrawer->SetAspect( anAspect, anAspect->GetAspectName() );
164 if ( !GetContext().IsNull() )
165 GetContext()->CurrentViewer()->Update();
169 void AIS2D_InteractiveObject::SetAspect( const Handle(Prs2d_AspectRoot)& anAspect,
170 const Handle(Graphic2d_Primitive)& aPrim ) {
172 if ( ( GetContext().IsNull() ) || ( !IsIn(aPrim) ) ) return;
174 switch ( anAspect->GetAspectName() ) {
176 case Prs2d_AN_LINE: {
178 if ( aPrim->IsKind(STANDARD_TYPE(Graphic2d_Line)) ) {
180 Handle(Prs2d_AspectLine) theAspLine =
181 Handle(Prs2d_AspectLine)::DownCast( anAspect );
183 Quantity_Color aColor;
184 Aspect_TypeOfLine aType;
185 Aspect_WidthOfLine aWidth;
187 Quantity_Color aIntColor;
188 Graphic2d_TypeOfPolygonFilling aTypeFill;
189 Standard_Integer aTile;
190 Standard_Boolean aDrawEdge;
192 theAspLine->ValuesOfLine( aColor, aType, aWidth );
193 theAspLine->ValuesOfPoly( aIntColor, aTypeFill, aTile, aDrawEdge );
195 Standard_Integer colorInd = theAspLine->ColorIndex();
196 Standard_Integer typeInd = theAspLine->TypeIndex();
197 Standard_Integer widthInd = theAspLine->WidthIndex();
198 Standard_Integer colorIntInd = theAspLine->InterColorIndex();
201 colorInd = GetContext()->InitializeColor( aColor );
202 theAspLine->SetColorIndex( colorInd );
206 typeInd = GetContext()->InitializeStyle( aType );
207 theAspLine->SetTypeIndex( typeInd );
211 widthInd = GetContext()->InitializeWidth( aWidth );
212 theAspLine->SetWidthIndex( widthInd );
215 if ( !colorIntInd ) {
216 colorIntInd = GetContext()->InitializeColor( aIntColor );
217 theAspLine->SetIntColorInd( colorIntInd );
220 Handle(Graphic2d_Line) theLine = Handle(Graphic2d_Line)::DownCast( aPrim );
222 theLine->SetColorIndex( colorInd );
223 theLine->SetTypeIndex( typeInd );
224 theLine->SetWidthIndex( widthInd );
226 theLine->SetInteriorColorIndex( colorIntInd );
227 theLine->SetTypeOfPolygonFilling( aTypeFill );
228 theLine->SetInteriorPattern( aTile );
229 theLine->SetDrawEdge( aDrawEdge );
231 if ( !myAspects.IsBound(aPrim) )
232 myAspects.Bind( theLine, theAspLine );
234 myAspects( theLine ) = theAspLine;
236 } // end if STANDARD_TYPE is Graphic2d_Line
239 } // end case Prs2d_AN_LINE
241 case Prs2d_AN_HIDDENLINE: {
244 case Prs2d_AN_TEXT: {
247 case Prs2d_AN_HIDINGPOLY: {
250 case Prs2d_AN_HIDINGTEXT: {
253 case Prs2d_AN_FRAMEDTEXT: {
256 case Prs2d_AN_LAST: {
259 case Prs2d_AN_UNKNOWN: {
265 myDrawer->SetAspect( anAspect, anAspect->GetAspectName() );
266 GetContext()->CurrentViewer()->Update();
270 Handle(Prs2d_AspectRoot) AIS2D_InteractiveObject::GetAspect
271 ( const Handle(Graphic2d_Primitive)& aPrim ) const {
273 return myAspects( aPrim );
276 Standard_Boolean AIS2D_InteractiveObject::HasAspect
277 ( const Handle(Graphic2d_Primitive)& aPrim ) const {
279 return myAspects.IsBound( aPrim );
282 Standard_Boolean AIS2D_InteractiveObject::HasInteractiveContext() const {
283 return ( ! myICTX.IsNull() );
286 Handle(AIS2D_InteractiveContext) AIS2D_InteractiveObject::GetContext() const {
290 void AIS2D_InteractiveObject::SetContext( const Handle(AIS2D_InteractiveContext)& aCtx) {
293 if ( myDrawer.IsNull() )
294 myDrawer = new Prs2d_Drawer;
298 void AIS2D_InteractiveObject::SelectPrimitive (const Standard_Integer anIndex, const Standard_Boolean append )
302 for ( Standard_Integer i = 1; i <= mySelectedPrimSeq->Length(); i++ )
303 mySelectedPrimSeq->Value( i )->GetPrimitive()->Unhighlight();
304 mySelectedPrimSeq->Clear();
307 // select new primitive
308 SetPickedIndex( anIndex );
311 Standard_Boolean AIS2D_InteractiveObject::PrimitiveExist( const Prs2d_AspectName aName) const {
313 Standard_Boolean isFound = Standard_False;
315 for ( Standard_Integer i = 1; i <= Length(); i++ )
318 case Prs2d_AN_LINE: {
319 if ( Primitive(i)->IsKind(STANDARD_TYPE(Graphic2d_Line)) )
320 isFound = Standard_True;
323 case Prs2d_AN_HIDDENLINE: {
326 case Prs2d_AN_TEXT: {
329 case Prs2d_AN_HIDINGPOLY: {
332 case Prs2d_AN_HIDINGTEXT: {
335 case Prs2d_AN_FRAMEDTEXT: {
338 case Prs2d_AN_LAST: {
341 case Prs2d_AN_UNKNOWN: {
350 void AIS2D_InteractiveObject::AddDetectPrim ( const Handle(Graphic2d_Primitive)& aPrim,
351 const Standard_Integer anInd) {
353 Handle(AIS2D_PrimitiveArchit) thePA = new AIS2D_PrimitiveArchit( aPrim, anInd );
354 myDetectedPrimSeq->Append( thePA );
358 void AIS2D_InteractiveObject::AddSelectPrim ( const Handle(Graphic2d_Primitive)& aPrim,
359 const Standard_Integer anInd) {
361 Handle(AIS2D_PrimitiveArchit) thePA = new AIS2D_PrimitiveArchit( aPrim, anInd );
362 mySelectedPrimSeq->Append( thePA );
366 void AIS2D_InteractiveObject::RemoveSelectPrim ( const Handle(Graphic2d_Primitive)& aPrim,
367 const Standard_Integer anInd) {
369 if ( mySelectedPrimSeq->IsEmpty() ) return;
370 for ( int i = 1; i <= mySelectedPrimSeq->Length(); ++i )
371 if ( mySelectedPrimSeq->Value(i)->GetPrimitive() == aPrim &&
372 mySelectedPrimSeq->Value(i)->GetIndex() == anInd ) {
373 mySelectedPrimSeq->Remove(i);
378 void AIS2D_InteractiveObject::SetSelSeqPrim( const Handle(AIS2D_HSequenceOfPrimArchit)& aSeq ) {
380 mySelectedPrimSeq = aSeq;
384 void AIS2D_InteractiveObject::ClearSeqDetPrim() {
386 myDetectedPrimSeq->Clear();
390 void AIS2D_InteractiveObject::ClearSeqSelPrim() {
392 mySelectedPrimSeq->Clear();
396 Handle(AIS2D_HSequenceOfPrimArchit) AIS2D_InteractiveObject::GetDetectSeqPrim() const {
398 return myDetectedPrimSeq;
402 Handle(AIS2D_HSequenceOfPrimArchit) AIS2D_InteractiveObject::GetSelectedSeqPrim() const {
404 return mySelectedPrimSeq;
408 void AIS2D_InteractiveObject::Save(Aspect_FStream& aFStream) const
410 int lnOfPr = Length();
412 *aFStream << "AIS2D_InteractiveObject" << endl;
413 for (int j = 1; j <= lnOfPr; j++)
415 Handle(Graphic2d_Primitive) thePrm = this->Primitive(j);
416 thePrm->Save(aFStream);
420 void AIS2D_InteractiveObject::Retrieve(Aspect_IFStream& anIFStream) const
423 anIFStream->getline(buf, 100);
424 while (! anIFStream->eof())
426 if (! strcmp(buf, "Graphic2d_Segment"))
428 Graphic2d_Segment::Retrieve(anIFStream, this);
430 else if (! strcmp(buf, "Graphic2d_InfiniteLine"))
432 Graphic2d_InfiniteLine::Retrieve(anIFStream, this);
434 else if (! strcmp(buf, "Graphic2d_Polyline"))
436 Graphic2d_Polyline::Retrieve(anIFStream, this);
438 else if (! strcmp(buf, "Graphic2d_PolylineMarker"))
440 Graphic2d_PolylineMarker::Retrieve(anIFStream, this);
442 else if (! strcmp(buf, "Graphic2d_Circle"))
444 Graphic2d_Circle::Retrieve(anIFStream, this);
446 else if (! strcmp(buf, "Graphic2d_CircleMarker"))
448 Graphic2d_CircleMarker::Retrieve(anIFStream, this);
450 else if (! strcmp(buf, "Graphic2d_Ellips"))
452 Graphic2d_Ellips::Retrieve(anIFStream, this);
454 else if (! strcmp(buf, "Graphic2d_EllipsMarker"))
456 Graphic2d_EllipsMarker::Retrieve(anIFStream, this);
458 else if (! strcmp(buf, "GGraphic2d_Curve"))
460 GGraphic2d_Curve::Retrieve(anIFStream, this);
462 anIFStream->getline(buf, 100);