0025284: Problems with standard MFC samples
[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
47162471 25IMPLEMENT_DYNCREATE(CImportExportDoc, OCC_3dDoc)
7fd59977 26
47162471 27BEGIN_MESSAGE_MAP(CImportExportDoc, OCC_3dDoc)
7fd59977 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()
47162471 51: OCC_3dDoc (false)
7fd59977 52{
7fd59977 53/*
54 // TRIHEDRON
55 Handle(AIS_Trihedron) aTrihedron;
56 Handle(Geom_Axis2Placement) aTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
57 aTrihedron=new AIS_Trihedron(aTrihedronAxis);
58 myAISContext->Display(aTrihedron);
59*/
60
61 m_pcoloredshapeList = new CColoredShapes();
62}
63
64CImportExportDoc::~CImportExportDoc()
65{
66 if( m_pcoloredshapeList ) delete m_pcoloredshapeList;
67}
68
69
70/////////////////////////////////////////////////////////////////////////////
71// CSerializeDoc serialization
72
73void CImportExportDoc::Serialize(CArchive& ar)
74{
75 if (ar.IsStoring())
76 {
77 // Put the curent CColoredShape in the archive
78 ar << m_pcoloredshapeList;
79 }
80 else
81 {
82 // Read from the archive the current CColoredShape
83 ar >> m_pcoloredshapeList;
84
85 // Display the new object
86 m_pcoloredshapeList->Display(myAISContext);
87 }
88}
89
90
91/*
92void CImportExportDoc::OnWindowNew3d()
93{
94 ((CImportExportApp*)AfxGetApp())->CreateView3D(this);
95}
96*/
97
98// nCmdShow could be : ( default is SW_RESTORE )
99// SW_HIDE SW_SHOWNORMAL SW_NORMAL
100// SW_SHOWMINIMIZED SW_SHOWMAXIMIZED
101// SW_MAXIMIZE SW_SHOWNOACTIVATE
102// SW_SHOW SW_MINIMIZE
103// SW_SHOWMINNOACTIVE SW_SHOWNA
104// SW_RESTORE SW_SHOWDEFAULT
105// SW_MAX
106
107// use pViewClass = RUNTIME_CLASS( CImportExportView3D ) for 3D Views
108
109void CImportExportDoc::ActivateFrame(CRuntimeClass* pViewClass,int nCmdShow)
110{
111 POSITION position = GetFirstViewPosition();
112 while (position != (POSITION)NULL)
113 {
114 CView* pCurrentView = (CView*)GetNextView(position);
115 if(pCurrentView->IsKindOf(pViewClass) )
116 {
117 ASSERT_VALID(pCurrentView);
118 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
119 ASSERT(pParentFrm != (CFrameWnd *)NULL);
120 // simply make the frame window visible
121 pParentFrm->ActivateFrame(nCmdShow);
122 }
123 }
124
125}
126
127/////////////////////////////////////////////////////////////////////////////
128// CImportExportDoc diagnostics
129
130#ifdef _DEBUG
131void CImportExportDoc::AssertValid() const
132{
133 CDocument::AssertValid();
134}
135
136void CImportExportDoc::Dump(CDumpContext& dc) const
137{
138 CDocument::Dump(dc);
139}
140#endif //_DEBUG
141
142/////////////////////////////////////////////////////////////////////////////
143// CImportExportDoc commands
144
145
146void CImportExportDoc::OnFileImportBrep()
147{
148 Handle(TopTools_HSequenceOfShape) aSeqOfShape = CImportExport::ReadBREP();
149 for(int i=1;i<= aSeqOfShape->Length();i++)
150 {
151 m_pcoloredshapeList->Add(Quantity_NOC_YELLOW, aSeqOfShape->Value(i));
152 m_pcoloredshapeList->Display(myAISContext);
153 }
154 Fit();
155}
156
157void CImportExportDoc::OnFileImportCSFDB()
158{
159 Handle(TopTools_HSequenceOfShape) aSeqOfShape = CImportExport::ReadCSFDB();
160 for(int i=1;i<= aSeqOfShape->Length();i++)
161 {
162 m_pcoloredshapeList->Add(Quantity_NOC_YELLOW, aSeqOfShape->Value(i));
163 m_pcoloredshapeList->Display(myAISContext);
164 }
165 Fit();
166}
167void CImportExportDoc::OnFileExportCSFDB()
168{ CImportExport::SaveCSFDB(myAISContext);}
169
170void CImportExportDoc::OnFileImportIges()
171{
172 Handle(TopTools_HSequenceOfShape) aSeqOfShape = CImportExport::ReadIGES();
173 for(int i=1;i<= aSeqOfShape->Length();i++)
174 {
175 m_pcoloredshapeList->Add(Quantity_NOC_YELLOW, aSeqOfShape->Value(i));
176 m_pcoloredshapeList->Display(myAISContext);
177 }
178 Fit();
179}
180void CImportExportDoc::OnFileExportIges()
181{ CImportExport::SaveIGES(myAISContext);}
182
183void CImportExportDoc::OnFileImportStep()
184{
185 Handle(TopTools_HSequenceOfShape) aSeqOfShape = CImportExport::ReadSTEP();
186 for(int i=1;i<= aSeqOfShape->Length();i++)
187 {
188 m_pcoloredshapeList->Add(Quantity_NOC_YELLOW, aSeqOfShape->Value(i));
189 m_pcoloredshapeList->Display(myAISContext);
190 }
191 Fit();
192}
193void CImportExportDoc::OnFileExportStep()
194{ CImportExport::SaveSTEP(myAISContext);}
195
196
197void CImportExportDoc::OnFileExportVrml()
198{ CImportExport::SaveVRML(myAISContext);}
199
200void CImportExportDoc::OnFileExportStl()
201{ CImportExport::SaveSTL(myAISContext);}
202
203void CImportExportDoc::Popup(const Standard_Integer x,
204 const Standard_Integer y ,
205 const Handle(V3d_View)& aView )
206{
207 Standard_Integer PopupMenuNumber=0;
208 myAISContext->InitCurrent();
209 if (myAISContext->MoreCurrent())
210 PopupMenuNumber=1;
211
212 CMenu menu;
213 VERIFY(menu.LoadMenu(IDR_Popup3D));
214 CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber);
215
216 ASSERT(pPopup != NULL);
217 if (PopupMenuNumber == 1) // more than 1 object.
218 {
219 bool OneOrMoreInShading = false;
220 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
221 if (myAISContext->IsDisplayed(myAISContext->Current(),1)) OneOrMoreInShading=true;
222 if(!OneOrMoreInShading)
223 pPopup->EnableMenuItem(5, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
224 }
225
226 POINT winCoord = { x , y };
227 Handle(WNT_Window) aWNTWindow=
228 Handle(WNT_Window)::DownCast(aView->Window());
229 ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord);
230 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y ,
231 AfxGetMainWnd());
232
233
234}
235
236void CImportExportDoc::OnBox()
237{
238 AIS_ListOfInteractive aList;
239 myAISContext->DisplayedObjects(aList);
240 AIS_ListIteratorOfListOfInteractive aListIterator;
241 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
242 myAISContext->Remove(aListIterator.Value());
243 }
244
245 BRepPrimAPI_MakeBox B(200.,150.,100.);
246
247 m_pcoloredshapeList->Add(Quantity_NOC_YELLOW, B.Shape());
248
249 m_pcoloredshapeList->Display(myAISContext);
250 Fit();
251
252 // document has been modified
253 SetModifiedFlag(TRUE);
254}
255
256void CImportExportDoc::OnCylinder()
257{
258 AIS_ListOfInteractive aList;
259 myAISContext->DisplayedObjects(aList);
260 AIS_ListIteratorOfListOfInteractive aListIterator;
261 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
262 myAISContext->Remove(aListIterator.Value());
263 }
264
265 BRepPrimAPI_MakeCylinder C(50.,200.);
266
267 m_pcoloredshapeList->Add(Quantity_NOC_GREEN, C.Shape());
268
269 m_pcoloredshapeList->Display(myAISContext);
270 Fit();
271
272 // document has been modified
273 SetModifiedFlag(TRUE);
b96f3bea 274}
275void CImportExportDoc::OnObjectRemove()
276
277{
278 for(GetAISContext()->InitCurrent();GetAISContext()->MoreCurrent();GetAISContext()->NextCurrent()) {
279 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(GetAISContext()->Current());
280 if(!aShape.IsNull()) {
281 m_pcoloredshapeList->Remove(aShape->Shape());
282 }
283 }
284 OCC_3dBaseDoc::OnObjectRemove();
285}
286
287void CImportExportDoc::OnObjectErase()
288
289{
290 for(GetAISContext()->InitCurrent();GetAISContext()->MoreCurrent();GetAISContext()->NextCurrent()) {
291 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(GetAISContext()->Current());
292 if(!aShape.IsNull()) {
293 m_pcoloredshapeList->Remove(aShape->Shape());
294 }
295 }
296 OCC_3dBaseDoc::OnObjectErase();
297}
298
299void CImportExportDoc::OnObjectDisplayall()
300
301{
302 OCC_3dBaseDoc::OnObjectDisplayall();
7fd59977 303}