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 IMPLEMENT_SERIAL(CColoredShapes, CObject,1);
28 // This schema contains all the Persistent Geometry and Topology
29 #include <ShapeSchema.hxx>
31 // Tools to store TopoDS_Shape
32 #include <MgtBRep.hxx>
33 #include <PTopoDS_HShape.hxx>
34 #include <PTColStd_TransientPersistentMap.hxx>
35 #include <TopoDS_Shape.hxx>
37 // Tools to put Persistent Object in an archive
38 #include <FSD_Archive.hxx>
39 #include <Storage_Data.hxx>
40 #include <Storage_HSeqOfRoot.hxx>
41 #include <Storage_Root.hxx>
42 #include <PTColStd_PersistentTransientMap.hxx>
44 void CColoredShapes::Serialize(CArchive & ar)
46 CObject::Serialize(ar);
51 // the applicative Schema containing Persistent Topology and Geometry
52 // Note that it inherits from the class Storage_Schema
53 Handle(ShapeSchema) s = new ShapeSchema;
57 // Write number of shapes to be serialized
59 ar << (int)m_colorMap.Extent();
61 for ( TopoDS_ListIteratorOfListOfShape iter(m_shapeList); iter.More(); iter.Next() )
63 //Create the persistent Shape
64 PTColStd_TransientPersistentMap aMap;
66 Handle(PTopoDS_HShape) aPShape =
67 MgtBRep::Translate(iter.Value(), aMap, MgtBRep_WithoutTriangle);
69 // Store the Persistent shape in the archive
70 Handle(Storage_Data) d = new Storage_Data;
71 d->AddRoot("ObjectName", aPShape);
75 if (d->ErrorStatus() != Storage_VSOk)
77 ::MessageBox(NULL, " Error while writing... ", " Error ",MB_OK) ;
80 // Store the color in the archive
81 ar << (Standard_Integer)m_colorMap.Find(iter.Value());
86 // Get numbe of stored shapes
91 Quantity_NameOfColor theColor;
94 for ( int i = 0; i < nbShapes; i++ )
96 // Read the Persistent Shape from the archive
97 Handle(Storage_Data) d = s->Read( f );
98 Handle(Storage_HSeqOfRoot) roots = d->Roots();
99 Handle(Standard_Persistent) p;
100 Handle(Storage_Root) r;
101 Handle(PTopoDS_HShape) aPShape;
102 TopoDS_Shape theShape;
106 aPShape = Handle(PTopoDS_HShape)::DownCast(p);
109 PTColStd_PersistentTransientMap aMap;
111 MgtBRep::Translate(aPShape,aMap,theShape,MgtBRep_WithoutTriangle);
113 m_shapeList.Append(theShape);
115 // Read the Color from the archive
117 theColor = (Quantity_NameOfColor) tmp;
118 m_colorMap.Bind(theShape, theColor);
123 void CColoredShapes::Display(Handle(AIS_InteractiveContext)& anAIScontext)
125 for ( TopoDS_ListIteratorOfListOfShape iter(m_shapeList); iter.More(); iter.Next() )
127 Handle(AIS_Shape) ais = new AIS_Shape(iter.Value());
128 anAIScontext->SetColor(ais, (Quantity_NameOfColor)m_colorMap.Find(iter.Value()));
129 anAIScontext->SetMaterial(ais, Graphic3d_NOM_GOLD, Standard_False);
130 anAIScontext->Display(ais, Standard_False);