1 // ColoredShapes.cpp: implementation of the CColoredShape class.
3 //////////////////////////////////////////////////////////////////////
9 #include "ColoredShapes.h"
11 //////////////////////////////////////////////////////////////////////
12 // Construction/Destruction
13 //////////////////////////////////////////////////////////////////////
15 CColoredShapes::CColoredShapes()
20 void CColoredShapes::Add(const Quantity_NameOfColor aColor, const TopoDS_Shape& aShape)
22 m_shapeList.Append(aShape);
23 m_colorMap.Bind(aShape, aColor);
26 void CColoredShapes::Remove(const TopoDS_Shape& aShape)
28 m_colorMap.UnBind(aShape);
29 for ( TopoDS_ListIteratorOfListOfShape iter(m_shapeList); iter.More(); iter.Next() ) {
30 if(iter.Value() == aShape) {
31 m_shapeList.Remove(iter);
37 IMPLEMENT_SERIAL(CColoredShapes, CObject,1);
39 // This schema contains all the Persistent Geometry and Topology
40 #include <ShapeSchema.hxx>
42 // Tools to store TopoDS_Shape
43 #include <MgtBRep.hxx>
44 #include <PTopoDS_HShape.hxx>
45 #include <PTColStd_TransientPersistentMap.hxx>
46 #include <TopoDS_Shape.hxx>
48 // Tools to put Persistent Object in an archive
49 #include <FSD_Archive.hxx>
50 #include <Storage_Data.hxx>
51 #include <Storage_HSeqOfRoot.hxx>
52 #include <Storage_Root.hxx>
53 #include <PTColStd_PersistentTransientMap.hxx>
55 void CColoredShapes::Serialize(CArchive & ar)
57 CObject::Serialize(ar);
62 // the applicative Schema containing Persistent Topology and Geometry
63 // Note that it inherits from the class Storage_Schema
64 Handle(ShapeSchema) s = new ShapeSchema;
68 // Write number of shapes to be serialized
70 ar << (int)m_colorMap.Extent();
72 for ( TopoDS_ListIteratorOfListOfShape iter(m_shapeList); iter.More(); iter.Next() )
74 //Create the persistent Shape
75 PTColStd_TransientPersistentMap aMap;
77 Handle(PTopoDS_HShape) aPShape =
78 MgtBRep::Translate(iter.Value(), aMap, MgtBRep_WithoutTriangle);
80 // Store the Persistent shape in the archive
81 Handle(Storage_Data) d = new Storage_Data;
82 d->AddRoot("ObjectName", aPShape);
86 if (d->ErrorStatus() != Storage_VSOk)
88 ::MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error while writing... ", L" Error ", MB_OK);
91 // Store the color in the archive
92 ar << (Standard_Integer)m_colorMap.Find(iter.Value());
97 // Get numbe of stored shapes
101 Standard_Integer tmp;
102 Quantity_NameOfColor theColor;
104 // Reading all shapes
105 for ( int i = 0; i < nbShapes; i++ )
107 // Read the Persistent Shape from the archive
108 Handle(Storage_Data) d = s->Read( f );
109 Handle(Storage_HSeqOfRoot) roots = d->Roots();
110 Handle(Standard_Persistent) p;
111 Handle(Storage_Root) r;
112 Handle(PTopoDS_HShape) aPShape;
113 TopoDS_Shape theShape;
117 aPShape = Handle(PTopoDS_HShape)::DownCast(p);
120 PTColStd_PersistentTransientMap aMap;
122 MgtBRep::Translate(aPShape,aMap,theShape,MgtBRep_WithoutTriangle);
124 m_shapeList.Append(theShape);
126 // Read the Color from the archive
128 theColor = (Quantity_NameOfColor) tmp;
129 m_colorMap.Bind(theShape, theColor);
134 void CColoredShapes::Display(Handle(AIS_InteractiveContext)& anAIScontext)
136 for ( TopoDS_ListIteratorOfListOfShape iter(m_shapeList); iter.More(); iter.Next() )
138 Handle(AIS_Shape) ais = new AIS_Shape(iter.Value());
139 anAIScontext->SetColor(ais, (Quantity_NameOfColor)m_colorMap.Find(iter.Value()));
140 anAIScontext->SetMaterial(ais, Graphic3d_NOM_GOLD, Standard_False);
141 anAIScontext->Display(ais, Standard_False);