Small update
[occt.git] / samples / mfc / standard / 05_ImportExport / src / ImportExportDoc.cpp
CommitLineData
7fd59977 1// ImportExportDoc.cpp : implementation of the CImportExportDoc class
2//
3
4
5#include "stdafx.h"
6#include "ImportExportApp.h"
7
8#include "ImportExportDoc.h"
9
10#include <ImportExport/ImportExport.h>
11
12#include <AISDialogs.h>
13#include "res/resource.h"
14
15
16#ifdef _DEBUG
17//#define new DEBUG_NEW // by cascade
18#undef THIS_FILE
19static char THIS_FILE[] = __FILE__;
20#endif
21
22/////////////////////////////////////////////////////////////////////////////
23// CImportExportDoc
24
25IMPLEMENT_DYNCREATE(CImportExportDoc, CDocument)
26
27BEGIN_MESSAGE_MAP(CImportExportDoc, OCC_3dBaseDoc)
28 //{{AFX_MSG_MAP(CImportExportDoc)
29 ON_COMMAND(ID_FILE_IMPORT_BREP, OnFileImportBrep)
30 ON_COMMAND(ID_FILE_IMPORT_CSFDB, OnFileImportCSFDB)
31 ON_COMMAND(ID_FILE_EXPORT_CSFDB, OnFileExportCSFDB)
32 ON_COMMAND(ID_FILE_IMPORT_IGES, OnFileImportIges)
33 ON_COMMAND(ID_FILE_EXPORT_IGES, OnFileExportIges)
34 ON_COMMAND(ID_FILE_IMPORT_STEP, OnFileImportStep)
35 ON_COMMAND(ID_FILE_EXPORT_STEP, OnFileExportStep)
36 ON_COMMAND(ID_FILE_EXPORT_VRML, OnFileExportVrml)
37 ON_COMMAND(ID_FILE_EXPORT_STL, OnFileExportStl)
38 ON_COMMAND(ID_BOX, OnBox)
39 ON_COMMAND(ID_Cylinder, OnCylinder)
b96f3bea 40 ON_COMMAND(ID_OBJECT_REMOVE, OnObjectRemove)
41 ON_COMMAND(ID_OBJECT_ERASE, OnObjectErase)
42 ON_COMMAND(ID_OBJECT_DISPLAYALL, OnObjectDisplayall)
7fd59977 43 //}}AFX_MSG_MAP
44
45END_MESSAGE_MAP()
46
47/////////////////////////////////////////////////////////////////////////////
48// CImportExportDoc construction/destruction
49
50CImportExportDoc::CImportExportDoc()
51{
52 /*
53 Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice =
54 ((CImportExportApp*)AfxGetApp())->GetGraphicDevice();
55
56 TCollection_ExtendedString a3DName("Visu3D");
57 myViewer = new V3d_Viewer(theGraphicDevice,a3DName.ToExtString(),"", 1000.0,
58 V3d_XposYnegZpos, Quantity_NOC_GRAY30,
59 V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT,
60 Standard_True, Standard_False);
61
62 myViewer->SetDefaultLights();
63 myViewer->SetLightOn();
64
65 myAISContext =new AIS_InteractiveContext(myViewer);
66
67 */
68/*
69 // TRIHEDRON
70 Handle(AIS_Trihedron) aTrihedron;
71 Handle(Geom_Axis2Placement) aTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
72 aTrihedron=new AIS_Trihedron(aTrihedronAxis);
73 myAISContext->Display(aTrihedron);
74*/
75
76 m_pcoloredshapeList = new CColoredShapes();
77}
78
79CImportExportDoc::~CImportExportDoc()
80{
81 if( m_pcoloredshapeList ) delete m_pcoloredshapeList;
82}
83
84
85/////////////////////////////////////////////////////////////////////////////
86// CSerializeDoc serialization
87
88void CImportExportDoc::Serialize(CArchive& ar)
89{
90 if (ar.IsStoring())
91 {
92 // Put the curent CColoredShape in the archive
93 ar << m_pcoloredshapeList;
94 }
95 else
96 {
97 // Read from the archive the current CColoredShape
98 ar >> m_pcoloredshapeList;
99
100 // Display the new object
101 m_pcoloredshapeList->Display(myAISContext);
102 }
103}
104
105
106/*
107void CImportExportDoc::OnWindowNew3d()
108{
109 ((CImportExportApp*)AfxGetApp())->CreateView3D(this);
110}
111*/
112
113// nCmdShow could be : ( default is SW_RESTORE )
114// SW_HIDE SW_SHOWNORMAL SW_NORMAL
115// SW_SHOWMINIMIZED SW_SHOWMAXIMIZED
116// SW_MAXIMIZE SW_SHOWNOACTIVATE
117// SW_SHOW SW_MINIMIZE
118// SW_SHOWMINNOACTIVE SW_SHOWNA
119// SW_RESTORE SW_SHOWDEFAULT
120// SW_MAX
121
122// use pViewClass = RUNTIME_CLASS( CImportExportView3D ) for 3D Views
123
124void CImportExportDoc::ActivateFrame(CRuntimeClass* pViewClass,int nCmdShow)
125{
126 POSITION position = GetFirstViewPosition();
127 while (position != (POSITION)NULL)
128 {
129 CView* pCurrentView = (CView*)GetNextView(position);
130 if(pCurrentView->IsKindOf(pViewClass) )
131 {
132 ASSERT_VALID(pCurrentView);
133 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
134 ASSERT(pParentFrm != (CFrameWnd *)NULL);
135 // simply make the frame window visible
136 pParentFrm->ActivateFrame(nCmdShow);
137 }
138 }
139
140}
141
142/////////////////////////////////////////////////////////////////////////////
143// CImportExportDoc diagnostics
144
145#ifdef _DEBUG
146void CImportExportDoc::AssertValid() const
147{
148 CDocument::AssertValid();
149}
150
151void CImportExportDoc::Dump(CDumpContext& dc) const
152{
153 CDocument::Dump(dc);
154}
155#endif //_DEBUG
156
157/////////////////////////////////////////////////////////////////////////////
158// CImportExportDoc commands
159
160
161void CImportExportDoc::OnFileImportBrep()
162{
163 Handle(TopTools_HSequenceOfShape) aSeqOfShape = CImportExport::ReadBREP();
164 for(int i=1;i<= aSeqOfShape->Length();i++)
165 {
166 m_pcoloredshapeList->Add(Quantity_NOC_YELLOW, aSeqOfShape->Value(i));
167 m_pcoloredshapeList->Display(myAISContext);
168 }
169 Fit();
170}
171
172void CImportExportDoc::OnFileImportCSFDB()
173{
174 Handle(TopTools_HSequenceOfShape) aSeqOfShape = CImportExport::ReadCSFDB();
175 for(int i=1;i<= aSeqOfShape->Length();i++)
176 {
177 m_pcoloredshapeList->Add(Quantity_NOC_YELLOW, aSeqOfShape->Value(i));
178 m_pcoloredshapeList->Display(myAISContext);
179 }
180 Fit();
181}
182void CImportExportDoc::OnFileExportCSFDB()
183{ CImportExport::SaveCSFDB(myAISContext);}
184
185void CImportExportDoc::OnFileImportIges()
186{
187 Handle(TopTools_HSequenceOfShape) aSeqOfShape = CImportExport::ReadIGES();
188 for(int i=1;i<= aSeqOfShape->Length();i++)
189 {
190 m_pcoloredshapeList->Add(Quantity_NOC_YELLOW, aSeqOfShape->Value(i));
191 m_pcoloredshapeList->Display(myAISContext);
192 }
193 Fit();
194}
195void CImportExportDoc::OnFileExportIges()
196{ CImportExport::SaveIGES(myAISContext);}
197
198void CImportExportDoc::OnFileImportStep()
199{
200 Handle(TopTools_HSequenceOfShape) aSeqOfShape = CImportExport::ReadSTEP();
201 for(int i=1;i<= aSeqOfShape->Length();i++)
202 {
203 m_pcoloredshapeList->Add(Quantity_NOC_YELLOW, aSeqOfShape->Value(i));
204 m_pcoloredshapeList->Display(myAISContext);
205 }
206 Fit();
207}
208void CImportExportDoc::OnFileExportStep()
209{ CImportExport::SaveSTEP(myAISContext);}
210
211
212void CImportExportDoc::OnFileExportVrml()
213{ CImportExport::SaveVRML(myAISContext);}
214
215void CImportExportDoc::OnFileExportStl()
216{ CImportExport::SaveSTL(myAISContext);}
217
218void CImportExportDoc::Popup(const Standard_Integer x,
219 const Standard_Integer y ,
220 const Handle(V3d_View)& aView )
221{
222 Standard_Integer PopupMenuNumber=0;
223 myAISContext->InitCurrent();
224 if (myAISContext->MoreCurrent())
225 PopupMenuNumber=1;
226
227 CMenu menu;
228 VERIFY(menu.LoadMenu(IDR_Popup3D));
229 CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber);
230
231 ASSERT(pPopup != NULL);
232 if (PopupMenuNumber == 1) // more than 1 object.
233 {
234 bool OneOrMoreInShading = false;
235 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
236 if (myAISContext->IsDisplayed(myAISContext->Current(),1)) OneOrMoreInShading=true;
237 if(!OneOrMoreInShading)
238 pPopup->EnableMenuItem(5, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
239 }
240
241 POINT winCoord = { x , y };
242 Handle(WNT_Window) aWNTWindow=
243 Handle(WNT_Window)::DownCast(aView->Window());
244 ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord);
245 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y ,
246 AfxGetMainWnd());
247
248
249}
250
251void CImportExportDoc::OnBox()
252{
253 AIS_ListOfInteractive aList;
254 myAISContext->DisplayedObjects(aList);
255 AIS_ListIteratorOfListOfInteractive aListIterator;
256 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
257 myAISContext->Remove(aListIterator.Value());
258 }
259
260 BRepPrimAPI_MakeBox B(200.,150.,100.);
261
262 m_pcoloredshapeList->Add(Quantity_NOC_YELLOW, B.Shape());
263
264 m_pcoloredshapeList->Display(myAISContext);
265 Fit();
266
267 // document has been modified
268 SetModifiedFlag(TRUE);
269}
270
271void CImportExportDoc::OnCylinder()
272{
273 AIS_ListOfInteractive aList;
274 myAISContext->DisplayedObjects(aList);
275 AIS_ListIteratorOfListOfInteractive aListIterator;
276 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
277 myAISContext->Remove(aListIterator.Value());
278 }
279
280 BRepPrimAPI_MakeCylinder C(50.,200.);
281
282 m_pcoloredshapeList->Add(Quantity_NOC_GREEN, C.Shape());
283
284 m_pcoloredshapeList->Display(myAISContext);
285 Fit();
286
287 // document has been modified
288 SetModifiedFlag(TRUE);
b96f3bea 289}
290void CImportExportDoc::OnObjectRemove()
291
292{
293 for(GetAISContext()->InitCurrent();GetAISContext()->MoreCurrent();GetAISContext()->NextCurrent()) {
294 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(GetAISContext()->Current());
295 if(!aShape.IsNull()) {
296 m_pcoloredshapeList->Remove(aShape->Shape());
297 }
298 }
299 OCC_3dBaseDoc::OnObjectRemove();
300}
301
302void CImportExportDoc::OnObjectErase()
303
304{
305 for(GetAISContext()->InitCurrent();GetAISContext()->MoreCurrent();GetAISContext()->NextCurrent()) {
306 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(GetAISContext()->Current());
307 if(!aShape.IsNull()) {
308 m_pcoloredshapeList->Remove(aShape->Shape());
309 }
310 }
311 OCC_3dBaseDoc::OnObjectErase();
312}
313
314void CImportExportDoc::OnObjectDisplayall()
315
316{
317 OCC_3dBaseDoc::OnObjectDisplayall();
7fd59977 318}