021bd182ac7158f3db4f7a06a8193d827ea81613
[occt.git] / samples / mfc / standard / 04_Viewer3d / src / Viewer3dDoc.cpp
1 // Viewer3dDoc.cpp : implementation of the CViewer3dDoc class
2 //
3
4 #include "stdafx.h"
5 #include "Viewer3dApp.h"
6 #include "BoxRadius.h"
7 #include "DlgIsos.h"
8
9 #include "Viewer3dDoc.h"
10 #include "Viewer3dView.h"
11 #include "OffsetDlg.h"
12 #include "ResultDialog.h"
13 #include "User_Cylinder.hxx"
14
15 #include "AIS_Trihedron.hxx"
16 #include "Geom_Axis2Placement.hxx"
17
18 /////////////////////////////////////////////////////////////////////////////
19 // CViewer3dDoc
20
21 IMPLEMENT_DYNCREATE(CViewer3dDoc, CDocument)
22
23 BEGIN_MESSAGE_MAP(CViewer3dDoc, OCC_3dBaseDoc)
24         //{{AFX_MSG_MAP(CViewer3dDoc)
25         ON_COMMAND(ID_BOX, OnBox)
26         ON_COMMAND(ID_Cylinder, OnCylinder)
27         ON_COMMAND(ID_SPHERE, OnSphere)
28         ON_COMMAND(ID_ERASEALL, OnRemoveAll)
29         ON_COMMAND(ID_NBISOS, OnNbisos)
30         ON_COMMAND(ID_FACES, OnFaces)
31         ON_COMMAND(ID_EDGES, OnEdges)
32         ON_COMMAND(ID_VERTICES, OnVertices)
33         ON_COMMAND(ID_NEUTRAL, OnNeutral)
34         ON_COMMAND(ID_USERCYLINDER_CHANGEFACECOLOR, OnUsercylinderChangefacecolor)
35         ON_COMMAND(ID_FILLET3D, OnFillet3d)
36         ON_COMMAND(ID_CIRCLE, OnCircle)
37         ON_COMMAND(ID_LINE, OnLine)
38         ON_COMMAND(ID_OVERLAPPED_BOX, OnOverlappedBox)
39         ON_COMMAND(ID_OVERLAPPED_CYLINDER, OnOverlappedCylinder)
40         ON_COMMAND(ID_OVERLAPPED_SPHERE, OnOverlappedSphere)
41         ON_COMMAND(ID_POLYGON_OFFSETS, OnPolygonOffsets)
42         ON_UPDATE_COMMAND_UI(ID_POLYGON_OFFSETS, OnUpdatePolygonOffsets)
43         ON_UPDATE_COMMAND_UI(ID_Cylinder, OnUpdateCylinder)
44         ON_UPDATE_COMMAND_UI(ID_SPHERE, OnUpdateSphere)
45         ON_UPDATE_COMMAND_UI(ID_BOX, OnUpdateBox)
46         ON_UPDATE_COMMAND_UI(ID_OVERLAPPED_CYLINDER, OnUpdateOverlappedCylinder)
47         ON_UPDATE_COMMAND_UI(ID_OVERLAPPED_SPHERE, OnUpdateOverlappedSphere)
48         ON_UPDATE_COMMAND_UI(ID_OVERLAPPED_BOX, OnUpdateOverlappedBox)
49         ON_COMMAND(ID_OBJECT_REMOVE, OnObjectRemove)
50         ON_COMMAND(ID_OBJECT_ERASE, OnObjectErase)
51         ON_COMMAND(ID_OBJECT_DISPLAYALL, OnObjectDisplayall)
52         ON_COMMAND(ID_OBJECT_COLORED_MESH, OnObjectColoredMesh)
53         ON_UPDATE_COMMAND_UI(ID_OBJECT_COLORED_MESH, OnUpdateObjectColoredMesh)
54         ON_UPDATE_COMMAND_UI(ID_OBJECT_SHADING, OnUpdateObjectShading)
55         ON_UPDATE_COMMAND_UI(ID_OBJECT_WIREFRAME, OnUpdateObjectWireframe)
56         ON_COMMAND(ID_OPTIONS_TRIHEDRON_DYNAMIC_TRIHEDRON, OnOptionsTrihedronDynamicTrihedron)
57         ON_UPDATE_COMMAND_UI(ID_OPTIONS_TRIHEDRON_DYNAMIC_TRIHEDRON, OnUpdateOptionsTrihedronDynamicTrihedron)
58         ON_UPDATE_COMMAND_UI(ID_OPTIONS_TRIHEDRON_STATIC_TRIHEDRON, OnUpdateOptionsTrihedronStaticTrihedron)
59         ON_COMMAND(ID_OBJECT_MATERIAL, OnObjectMaterial)
60         ON_COMMAND(ID_TEXTURE_ON, OnTextureOn)
61         ON_COMMAND(ID_BUTTONNext, OnBUTTONNext)
62         ON_COMMAND(ID_BUTTONStart, OnBUTTONStart)
63         ON_COMMAND(ID_BUTTONRepeat, OnBUTTONRepeat)
64         ON_COMMAND(ID_BUTTONPrev, OnBUTTONPrev)
65         ON_COMMAND(ID_BUTTONEnd, OnBUTTONEnd)
66         ON_UPDATE_COMMAND_UI(ID_BUTTONNext, OnUpdateBUTTONNext)
67         ON_UPDATE_COMMAND_UI(ID_BUTTONPrev, OnUpdateBUTTONPrev)
68         ON_UPDATE_COMMAND_UI(ID_BUTTONStart, OnUpdateBUTTONStart)
69         ON_UPDATE_COMMAND_UI(ID_BUTTONRepeat, OnUpdateBUTTONRepeat)
70         ON_UPDATE_COMMAND_UI(ID_BUTTONEnd, OnUpdateBUTTONEnd)
71         ON_COMMAND(ID_FILE_NEW, OnFileNew)
72         ON_COMMAND(ID_DUMP_VIEW, OnDumpView)
73         //}}AFX_MSG_MAP
74 END_MESSAGE_MAP()
75
76 /////////////////////////////////////////////////////////////////////////////
77 // CViewer3dDoc construction/destruction
78
79 CViewer3dDoc::CViewer3dDoc()
80 {
81         myCylinder.Nullify();
82         mySphere.Nullify();
83         myBox.Nullify();
84         myOverlappedCylinder.Nullify();
85         myOverlappedSphere.Nullify();
86         myOverlappedBox.Nullify();
87         myOffsetDlg = NULL;
88         myStaticTrihedronAxisIsDisplayed = FALSE;
89
90         myState = -1;
91
92         isTextureSampleStarted = FALSE;
93 /*
94         // TODO: add one-time construction code here
95         Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice = 
96                 ((CViewer3dApp*)AfxGetApp())->GetGraphicDevice();
97
98         myViewer = new V3d_Viewer(theGraphicDevice,(short *) "Visu3D");
99         myViewer->SetDefaultLights();
100         myViewer->SetLightOn();
101 */
102
103 //      myViewer->SetDefaultBackgroundColor(Quantity_TOC_RGB, 0.,0.,0.);
104
105         myPresentation = OCCDemo_Presentation::Current;
106         myPresentation->SetDocument(this);
107
108
109         myAISContext->DefaultDrawer()->ShadingAspect()->SetColor(Quantity_NOC_CHARTREUSE1); 
110         myAISContext->DefaultDrawer()->ShadingAspect()->SetMaterial(Graphic3d_NOM_SILVER);
111
112         strcpy_s(myDataDir, "Data");
113         strcpy_s(myLastPath, ".");
114
115         /*
116         Handle(AIS_Trihedron) myTrihedron;
117         Handle(Geom_Axis2Placement) myTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
118         myTrihedron=new AIS_Trihedron(myTrihedronAxis);
119         myAISContext->Display(myTrihedron);
120         */
121 }
122
123 CViewer3dDoc::~CViewer3dDoc()
124 {
125 }
126
127 /////////////////////////////////////////////////////////////////////////////
128 // CViewer3dDoc diagnostics
129
130 #ifdef _DEBUG
131 void CViewer3dDoc::AssertValid() const
132 {
133         CDocument::AssertValid();
134 }
135
136 void CViewer3dDoc::Dump(CDumpContext& dc) const
137 {
138         CDocument::Dump(dc);
139 }
140 #endif //_DEBUG
141
142 /////////////////////////////////////////////////////////////////////////////
143 // CViewer3dDoc commands
144
145 void CViewer3dDoc::UpdateResultMessageDlg(CString Title, TCollection_AsciiString aMessage)
146 {
147     CString text(aMessage.ToCString());
148     myCResultDialog.SetText(text);
149
150     myCResultDialog.SetTitle(Title);
151 }
152
153 void CViewer3dDoc::OnBox() 
154 {
155         if(myBox.IsNull()){
156                 BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);
157
158
159                 myBox = new AIS_Shape(B.Shape());
160
161                 myAISContext->SetMaterial(myBox,Graphic3d_NOM_PEWTER);    
162                 myAISContext->SetDisplayMode(myBox,1);
163
164                 myAISContext->Display(myBox);   
165                 TCollection_AsciiString Message("\
166 BRepPrimAPI_MakeBox Box1(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
167                 ");
168                 
169                 UpdateResultMessageDlg("Create Box",Message);
170
171         }
172 }
173
174 void CViewer3dDoc::OnCylinder() 
175 {
176         if(myCylinder.IsNull()) {
177                 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
178
179                 //BRepPrimAPI_MakeCylinder C(CylAx2, 80.,200.);
180                 
181                 myCylinder = new User_Cylinder(CylAx2, 80.,200.);
182                 
183 //              myCylinder = new AIS_Shape(C.Shape());
184 /*
185                 myCylinder->SetTransparency(0.5);               
186
187                 myAISContext->SetColor(myCylinder,Quantity_NOC_WHITE); 
188                 myAISContext->SetMaterial(myCylinder,Graphic3d_NOM_SHINY_PLASTIC);    
189 */
190                 myAISContext->SetDisplayMode(myCylinder,1);
191
192                 myAISContext->Display(myCylinder);
193
194                 TCollection_AsciiString Message("\
195 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));\n\
196 C = new User_Cylinder(CylAx2, 80.,200.);;\n\
197                 ");
198                 
199                 UpdateResultMessageDlg("Create Cylinder",Message);
200
201         }
202 }
203
204 void CViewer3dDoc::OnSphere() 
205 {
206         if(mySphere.IsNull()){
207                 BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);
208
209                 mySphere = new AIS_Shape(S.Shape());
210                 
211                 myAISContext->SetMaterial(mySphere,Graphic3d_NOM_BRONZE);    
212                 myAISContext->SetDisplayMode(mySphere,1);
213
214                 myAISContext->Display(mySphere);
215                 TCollection_AsciiString Message("\
216 BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);\n\
217                 ");
218                 UpdateResultMessageDlg("Create Sphere",Message);
219         }
220 }
221
222 void CViewer3dDoc::OnRemoveAll() 
223
224 {
225         AIS_ListOfInteractive aListOfObjects;
226         myAISContext->ObjectsInside(aListOfObjects,AIS_KOI_Shape);
227
228         AIS_ListIteratorOfListOfInteractive aListIterator;
229         for(aListIterator.Initialize(aListOfObjects);aListIterator.More();aListIterator.Next()){
230                 myAISContext->Remove(aListIterator.Value());
231         }
232
233         myAISContext->Remove(myCylinder);
234
235
236         myCylinder.Nullify();
237         mySphere.Nullify();
238         myBox.Nullify();
239         myOverlappedCylinder.Nullify();
240         myOverlappedSphere.Nullify();
241         myOverlappedBox.Nullify();
242         if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
243                 myOffsetDlg->UpdateValues();
244 }
245
246 void CViewer3dDoc::OnOverlappedBox() 
247 {
248         OnBox();
249         if(myOverlappedBox.IsNull()){
250                 BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);
251
252                 BRepBuilderAPI_NurbsConvert aNurbsConvert(B.Shape());
253                 TopoDS_Shape aBoxShape2 = aNurbsConvert.Shape();
254
255
256                 myOverlappedBox = new AIS_Shape(aBoxShape2);
257
258                 myAISContext->SetMaterial(myOverlappedBox,Graphic3d_NOM_GOLD);    
259                 myAISContext->SetDisplayMode(myOverlappedBox,1);
260
261                 myAISContext->Display(myOverlappedBox); 
262                 TCollection_AsciiString Message("\
263 BRepPrimAPI_MakeBox Box1(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
264 \n\
265 BRepPrimAPI_MakeBox Box2(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
266 BRepBuilderAPI_NurbsConvert aNurbsConvert(Box2.Shape());\n\
267                 ");
268                 UpdateResultMessageDlg("Create overlapped boxes",Message);
269                 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
270                         myOffsetDlg->UpdateValues();
271
272
273         }
274 }
275
276 void CViewer3dDoc::OnOverlappedCylinder() 
277 {
278         OnCylinder();
279
280         if(myOverlappedCylinder.IsNull()){
281                 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
282                 BRepPrimAPI_MakeCylinder C(CylAx2, 80.,200.);
283
284                 BRepBuilderAPI_NurbsConvert aNurbsConvert(C.Shape());
285                 TopoDS_Shape aCylShape2 = aNurbsConvert.Shape();
286
287                 myOverlappedCylinder = new AIS_Shape(aCylShape2);
288
289         
290                 myAISContext->SetMaterial(myOverlappedCylinder,Graphic3d_NOM_GOLD);    
291                 myAISContext->SetDisplayMode(myOverlappedCylinder,1);
292
293                 myAISContext->Display(myOverlappedCylinder);
294
295                 TCollection_AsciiString Message("\
296 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));\n\
297 Cylinder1 = new User_Cylinder(CylAx2, 80.,200.);\n\
298 \n\
299 BRepPrimAPI_MakeCylinder Cylinder2(CylAx2, 80.,200.);\n\
300 BRepBuilderAPI_NurbsConvert aNurbsConvert(Cylinder2.Shape());\n\
301                 ");
302                 UpdateResultMessageDlg("Create overlapped cylinders",Message);
303                 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
304                         myOffsetDlg->UpdateValues();
305
306         }
307 }
308
309 void CViewer3dDoc::OnOverlappedSphere() 
310 {
311         OnSphere();
312         if(myOverlappedSphere.IsNull()){
313                 BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);
314
315                 BRepBuilderAPI_NurbsConvert aNurbsConvert(S.Shape());
316                 TopoDS_Shape aSphereShape2 = aNurbsConvert.Shape();
317
318                 myOverlappedSphere = new AIS_Shape(aSphereShape2);
319
320                 myAISContext->SetMaterial(myOverlappedSphere,Graphic3d_NOM_GOLD);    
321
322                 myAISContext->SetDisplayMode(myOverlappedSphere,1);
323
324                 myAISContext->Display(myOverlappedSphere);
325
326                 TCollection_AsciiString Message("\
327 BRepPrimAPI_MakeSphere Sphere1(gp_Pnt(0,300,0), 100.);\n\
328 \n\
329 BRepPrimAPI_MakeSphere Sphere2(gp_Pnt(0,300,0), 100.);\n\
330 BRepBuilderAPI_NurbsConvert aNurbsConvert(Sphere2.Shape());\n\
331                 ");
332                 UpdateResultMessageDlg("Create overlapped spheres",Message);
333                 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
334                         myOffsetDlg->UpdateValues();
335
336         }
337 }
338
339 void CViewer3dDoc::OnPolygonOffsets() 
340 {
341
342         myOffsetDlg = new COffsetDlg(this);
343         myOffsetDlg->Create(COffsetDlg::IDD,NULL);
344         myAISContext->UpdateCurrentViewer();
345
346 }
347
348 void CViewer3dDoc::OnUpdatePolygonOffsets(CCmdUI* pCmdUI) 
349 {
350         Standard_Integer aOffsetMode;
351         Standard_ShortReal aFactor;
352         Standard_ShortReal aCylUnits = 0;
353         Standard_ShortReal aSphereUnits = 0;
354         Standard_ShortReal aBoxUnits = 0;
355
356         BOOL IsOverlappedCylinderDisplayed = myAISContext->IsDisplayed(myOverlappedCylinder);
357         BOOL IsOverlappedSphereDisplayed = myAISContext->IsDisplayed(myOverlappedSphere);
358         BOOL IsOverlappedBoxDisplayed = myAISContext->IsDisplayed(myOverlappedBox);
359         BOOL IsAnyOverlappedObjectDisplayed = 
360                 IsOverlappedCylinderDisplayed || IsOverlappedSphereDisplayed || IsOverlappedBoxDisplayed;
361         
362         if(!myOverlappedCylinder.IsNull() && IsOverlappedCylinderDisplayed){
363                 myOverlappedCylinder->PolygonOffsets(aOffsetMode,aFactor,aCylUnits);
364         }
365         
366         if(!myOverlappedSphere.IsNull() && IsOverlappedSphereDisplayed){
367                 myOverlappedSphere->PolygonOffsets(aOffsetMode,aFactor,aSphereUnits);
368         }
369
370         if(!myOverlappedBox.IsNull() && IsOverlappedBoxDisplayed){
371                 myOverlappedBox->PolygonOffsets(aOffsetMode,aFactor,aBoxUnits);
372         }
373
374         if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
375                 pCmdUI->SetCheck(TRUE);
376         else
377                 pCmdUI->SetCheck(FALSE);
378         if (IsAnyOverlappedObjectDisplayed)
379                 if(myOffsetDlg)
380                         pCmdUI->Enable(!myOffsetDlg->IsWindowVisible());  
381                 else
382                         pCmdUI->Enable(TRUE);
383         else 
384                         pCmdUI->Enable(FALSE);
385         
386         
387 }
388
389 void CViewer3dDoc::OnUpdateCylinder(CCmdUI* pCmdUI) 
390 {
391         pCmdUI->Enable(myCylinder.IsNull()); 
392                 
393 }
394
395 void CViewer3dDoc::OnUpdateSphere(CCmdUI* pCmdUI) 
396 {
397         pCmdUI->Enable(mySphere.IsNull()); 
398                 
399 }
400
401 void CViewer3dDoc::OnUpdateBox(CCmdUI* pCmdUI) 
402 {
403         pCmdUI->Enable(myBox.IsNull()); 
404                 
405 }
406
407 void CViewer3dDoc::OnUpdateOverlappedCylinder(CCmdUI* pCmdUI) 
408 {
409         pCmdUI->Enable   (myOverlappedCylinder.IsNull()
410                                                 || myCylinder.IsNull());
411                 
412 }
413
414 void CViewer3dDoc::OnUpdateOverlappedSphere(CCmdUI* pCmdUI) 
415 {
416         pCmdUI->Enable   (myOverlappedSphere.IsNull()
417                                                 || mySphere.IsNull());
418 }
419
420 void CViewer3dDoc::OnUpdateOverlappedBox(CCmdUI* pCmdUI) 
421 {
422         pCmdUI->Enable   (myOverlappedBox.IsNull()
423                                                 || myBox.IsNull());
424 }
425
426 void CViewer3dDoc::OnObjectRemove() 
427
428 {
429
430         if(myAISContext->IsCurrent(myBox))
431                 myBox.Nullify();
432
433         if(myAISContext->IsCurrent(myCylinder))
434                 myCylinder.Nullify();
435
436         if(myAISContext->IsCurrent(mySphere))
437                 mySphere.Nullify();
438
439         if(myAISContext->IsCurrent(myOverlappedBox))
440                 myOverlappedBox.Nullify();
441
442         if(myAISContext->IsCurrent(myOverlappedCylinder))
443                 myOverlappedCylinder.Nullify();
444
445         if(myAISContext->IsCurrent(myOverlappedSphere))
446                 myOverlappedSphere.Nullify();
447
448         
449         for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->InitCurrent())
450                 myAISContext->Remove(myAISContext->Current(),Standard_True);
451
452         if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
453                 myOffsetDlg->UpdateValues();
454
455 }
456
457 void CViewer3dDoc::OnObjectErase() 
458
459 {
460         OCC_3dBaseDoc::OnObjectErase(); 
461         if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
462                 myOffsetDlg->UpdateValues();
463
464 }
465
466 void CViewer3dDoc::OnObjectDisplayall() 
467
468 {
469         OCC_3dBaseDoc::OnObjectDisplayall(); 
470         if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
471                 myOffsetDlg->UpdateValues();
472
473 }
474
475 Handle_User_Cylinder CViewer3dDoc::GetCylinder()
476 {
477         return myCylinder;
478 }
479
480
481 Handle_AIS_Shape CViewer3dDoc::GetSphere()
482 {
483         return mySphere;
484 }
485
486 Handle_AIS_Shape CViewer3dDoc::GetBox()
487 {
488         return myBox;
489 }
490
491 Handle_AIS_Shape CViewer3dDoc::GetOverlappedCylinder()
492 {
493         return myOverlappedCylinder;
494 }
495
496
497 Handle_AIS_Shape CViewer3dDoc::GetOverlappedSphere()
498 {
499         return myOverlappedSphere;
500 }
501
502 Handle_AIS_Shape CViewer3dDoc::GetOverlappedBox()
503 {
504         return myOverlappedBox;
505 }
506
507 void CViewer3dDoc::DragEvent(const Standard_Integer  x        ,
508                                                   const Standard_Integer  y        ,
509                                                   const Standard_Integer  TheState ,
510                                   const Handle(V3d_View)& aView    )
511 {
512         OCC_3dBaseDoc::DragEvent(x,y, TheState,aView);
513         if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
514                 myOffsetDlg->UpdateValues();
515 }
516
517 //-----------------------------------------------------------------------------------------
518 //
519 //-----------------------------------------------------------------------------------------
520 void CViewer3dDoc::InputEvent(const Standard_Integer  x     ,
521                                                    const Standard_Integer  y     ,
522                                    const Handle(V3d_View)& aView ) 
523 {
524         if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
525                 myOffsetDlg->UpdateValues();
526
527         Quantity_Color CSFColor ;
528         COLORREF MSColor ;
529         myAISContext->Select(); 
530 // Change the color of a selected face in a user cylinder
531         if (myState == FACE_COLOR) {
532                 myAISContext->InitSelected();
533                 if (myAISContext->MoreSelected()) {
534                         //Handle_AIS_InteractiveObject Current = myAISContext->Current() ;
535                         Handle_AIS_InteractiveObject Current = myAISContext->SelectedInteractive() ;
536                         if ( Current->HasColor () ) {
537                         CSFColor = myAISContext->Color(Current);
538                         MSColor = RGB (CSFColor.Red()*255.,CSFColor.Green()*255.,CSFColor.Blue()*255.);
539                         }
540                         else {
541                                 MSColor = RGB ( 255,255,255 ) ;
542                         }
543     
544                         CColorDialog dlgColor(MSColor);
545                         if (dlgColor.DoModal() == IDOK) {
546                                 MSColor = dlgColor.GetColor();
547                                 CSFColor = Quantity_Color (GetRValue(MSColor)/255.,
548                                                                                    GetGValue(MSColor)/255.,
549                                                                                    GetBValue(MSColor)/255.,Quantity_TOC_RGB); 
550                                 TopoDS_Shape S = myAISContext->SelectedShape();
551                                 Handle(Geom_Surface) Surface = BRep_Tool::Surface(TopoDS::Face(S));
552                                 if (Surface->IsKind(STANDARD_TYPE(Geom_Plane)))
553                                         //Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetPlanarFaceColor(CSFColor.Name());
554                                         Handle(User_Cylinder)::DownCast(myAISContext->SelectedInteractive())->SetPlanarFaceColor(CSFColor.Name());
555                                 else
556                                         //Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetCylindricalFaceColor(CSFColor.Name());
557                                         Handle(User_Cylinder)::DownCast(myAISContext->SelectedInteractive())->SetCylindricalFaceColor(CSFColor.Name());
558                                 //myAISContext->Redisplay(myAISContext->Current());
559                                 myAISContext->Redisplay(myAISContext->SelectedInteractive());
560                                 myState = -1;
561                                 myAISContext->CloseLocalContext();
562                         }
563                 }
564   TCollection_AsciiString Message ("\
565   TopoDS_Shape S = myAISContext->SelectedShape();  \n\
566   \n\
567   Handle(Geom_Surface) Surface = BRep_Tool::Surface(TopoDS::Face(S));  \n\
568   \n\
569   if (Surface->IsKind(STANDARD_TYPE(Geom_Plane)))  \n\
570         Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetPlanarFaceColor(CSFColor.Name());  \n\
571   else  \n\
572         Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetCylindricalFaceColor(CSFColor.Name());  \n\
573   \n\
574   myAISContext->Redisplay(myAISContext->Current());  \n\
575   \n\
576   myAISContext->CloseLocalContext();  \n\
577   \n\
578   \n\
579   NOTE: a User_Cylinder is an object defined by the user.  \n\
580   The User_Cylinder class inherit from the AIS_InteractiveObject   \n\
581   Cascade class, it's use is the same as an AIS_InteractiveObject.   \n\
582   Methods SetPlanarFaceColor and SetCylindricalFaceColor are also  \n\
583   defined in the User_Cylinder class.   \n\
584   \n");
585   
586         CString text(Message.ToCString());
587         myCResultDialog.SetTitle(CString("Change face color"));
588         myCResultDialog.SetText(text);
589         SetTitle(CString("Change face color"));
590   
591         }
592 }
593
594
595 //-----------------------------------------------------------------------------------------
596 //
597 //-----------------------------------------------------------------------------------------
598 void CViewer3dDoc::ShiftDragEvent(const Standard_Integer  x        ,
599                                                                            const Standard_Integer  y        ,
600                                                                            const Standard_Integer  TheState ,
601                                        const Handle(V3d_View)& aView    ) 
602 {
603     OCC_3dBaseDoc::ShiftDragEvent(x,y,TheState,aView);
604         if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
605                 myOffsetDlg->UpdateValues();
606 }
607
608
609 //-----------------------------------------------------------------------------------------
610 //
611 //-----------------------------------------------------------------------------------------
612
613 void CViewer3dDoc::ShiftInputEvent(const Standard_Integer  x       ,
614                                                                             const Standard_Integer  y       ,
615                                         const Handle(V3d_View)& aView   ) 
616 {
617     OCC_3dBaseDoc::ShiftInputEvent(x,y,aView);
618         if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
619                 myOffsetDlg->UpdateValues();
620
621 }
622
623 void CViewer3dDoc::OnObjectColoredMesh() 
624 {
625   for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->NextCurrent())
626           if (myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder))){
627                 myAISContext->ClearPrs(myAISContext->Current(),6,Standard_False);
628                         myAISContext->RecomputePrsOnly(myAISContext->Current(),Standard_False);
629                         myAISContext->SetDisplayMode(myAISContext->Current(),6);
630           }
631         
632 }
633
634 void CViewer3dDoc::OnUpdateObjectColoredMesh(CCmdUI* pCmdUI) 
635 {
636   bool CylinderIsCurrentAndDisplayed = false;
637   for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
638     //if ((myAISContext->IsDisplayed(myAISContext->Current(),1) || myAISContext->IsDisplayed(myAISContext->Current(),0))
639         //      && myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder))) 
640         if(myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
641                 CylinderIsCurrentAndDisplayed=true;
642   pCmdUI->Enable (CylinderIsCurrentAndDisplayed);       
643         
644 }
645
646 void CViewer3dDoc::OnUpdateObjectWireframe(CCmdUI* pCmdUI) 
647 {
648   bool OneOrMoreInShadingOrColoredMesh = false;
649   for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
650     if (myAISContext->IsDisplayed(myAISContext->Current(),1) || myAISContext->IsDisplayed(myAISContext->Current(),6)) 
651                 OneOrMoreInShadingOrColoredMesh=true;
652         pCmdUI->Enable (OneOrMoreInShadingOrColoredMesh);       
653 }
654
655
656 void CViewer3dDoc::OnUpdateObjectShading(CCmdUI* pCmdUI) 
657 {
658   bool OneOrMoreInWireframeOrColoredMesh = false;
659   for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
660     if (myAISContext->IsDisplayed(myAISContext->Current(),0) || myAISContext->IsDisplayed(myAISContext->Current(),6))
661                 OneOrMoreInWireframeOrColoredMesh=true;
662         pCmdUI->Enable (OneOrMoreInWireframeOrColoredMesh);     
663 }
664
665
666 void CViewer3dDoc::OnOptionsTrihedronDynamicTrihedron() 
667 {
668         if (myAISContext -> IsDisplayed(myTrihedron))
669         {
670                 myAISContext->Remove(myTrihedron);
671         }               
672         else
673         {
674                 Handle(Geom_Axis2Placement) myTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
675                 myTrihedron=new AIS_Trihedron(myTrihedronAxis);
676                 myAISContext->SetTrihedronSize(200, Standard_True);
677                 myAISContext->Display(myTrihedron);     
678         }               
679 }
680
681 void CViewer3dDoc::OnUpdateOptionsTrihedronDynamicTrihedron(CCmdUI* pCmdUI) 
682 {
683         if (myAISContext->IsDisplayed(myTrihedron))
684                 pCmdUI->SetCheck(1);
685         else
686                 pCmdUI->SetCheck(0);
687 }
688
689 void CViewer3dDoc::SetMyStaticTrihedronAxisIsDisplayed(BOOL IsDisplayed)
690 {
691         myStaticTrihedronAxisIsDisplayed = IsDisplayed;
692 }
693
694 void CViewer3dDoc::OnUpdateOptionsTrihedronStaticTrihedron(CCmdUI* pCmdUI) 
695 {
696         if (myStaticTrihedronAxisIsDisplayed)
697                 pCmdUI->SetCheck(1);
698         else
699                 pCmdUI->SetCheck(0);
700         
701 }
702
703 /*
704 void CViewer3dDoc::OnUpdateObjectColor(CCmdUI* pCmdUI) 
705 {
706   bool OneOrMoreInShadingOrWireframe = false;
707   for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
708     if (myAISContext->IsDisplayed(myAISContext->Current(),1)
709                 || myAISContext->IsDisplayed(myAISContext->Current(),0)) 
710                 OneOrMoreInShadingOrWireframe = true;
711   pCmdUI->Enable (OneOrMoreInShadingOrWireframe);       
712         
713 }
714 */
715
716 void  CViewer3dDoc::Popup( const Standard_Integer  x,
717                                                    const Standard_Integer  y ,
718                            const Handle(V3d_View)& aView   ) 
719 {
720   Standard_Integer PopupMenuNumber=0;
721  myAISContext->InitCurrent();
722   if (myAISContext->MoreCurrent()) {
723                 if (myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
724                         return;
725                 else 
726                         PopupMenuNumber = 1;
727         }
728
729   CMenu menu;
730   VERIFY(menu.LoadMenu(IDR_Popup3D));
731   CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber);
732
733   ASSERT(pPopup != NULL);
734    if (PopupMenuNumber == 1) // more than 1 object.
735   {
736     bool OneOrMoreInShading = false;
737         for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
738     if (myAISContext->IsDisplayed(myAISContext->Current(),1)) OneOrMoreInShading=true;
739         if(!OneOrMoreInShading)
740         pPopup->EnableMenuItem(5, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
741    }
742
743   POINT winCoord = { x , y };
744   Handle(WNT_Window) aWNTWindow=
745   Handle(WNT_Window)::DownCast(aView->Window());
746   ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord);
747   pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y , 
748                          AfxGetMainWnd());
749 }
750 //Set faces selection mode
751 void CViewer3dDoc::OnFaces() 
752 {
753         myAISContext->CloseAllContexts();
754         myAISContext->OpenLocalContext();
755         myAISContext->ActivateStandardMode(TopAbs_FACE);
756
757 TCollection_AsciiString Message ("\
758 myAISContext->OpenLocalContext();  \n\
759 \n\
760 myAISContext->ActivateStandardMode(TopAbs_FACE);  \n\
761 \n");
762
763         CString text(Message.ToCString());
764         myCResultDialog.SetTitle(CString("Standard mode: TopAbs_FACE"));
765         myCResultDialog.SetText(text);
766         SetTitle(CString("Standard mode: TopAbs_FACE"));
767 }
768
769 //Set edges selection mode
770 void CViewer3dDoc::OnEdges() 
771 {
772         myAISContext->CloseAllContexts();
773         myAISContext->OpenLocalContext();
774         myAISContext->ActivateStandardMode(TopAbs_EDGE);        
775
776 TCollection_AsciiString Message ("\
777 myAISContext->OpenLocalContext();  \n\
778 \n\
779 myAISContext->ActivateStandardMode(TopAbs_EDGE);  \n\
780 \n");
781
782         CString text(Message.ToCString());
783         myCResultDialog.SetTitle(CString("Standard mode: TopAbs_EDGE"));
784         myCResultDialog.SetText(text);
785         SetTitle(CString("Standard mode: TopAbs_EDGE"));
786 }
787
788 // Set vertices selection mode
789 void CViewer3dDoc::OnVertices() 
790 {
791         myAISContext->CloseAllContexts();
792         myAISContext->OpenLocalContext();
793         myAISContext->ActivateStandardMode(TopAbs_VERTEX);      
794
795 TCollection_AsciiString Message ("\
796 myAISContext->OpenLocalContext();  \n\
797 \n\
798 myAISContext->ActivateStandardMode(TopAbs_VERTEX);  \n\
799 \n");
800
801         CString text(Message.ToCString());
802         myCResultDialog.SetTitle(CString("Standard mode: TopAbs_VERTEX"));
803         myCResultDialog.SetText(text);
804         SetTitle(CString("Standard mode: TopAbs_VERTEX"));
805 }
806
807 //Neutral selection mode
808 void CViewer3dDoc::OnNeutral() 
809 {
810         myAISContext->CloseAllContexts();       
811
812 TCollection_AsciiString Message ("\
813 myAISContext->CloseAllContexts();  \n\
814 \n");
815
816         CString text(Message.ToCString());
817         myCResultDialog.SetTitle(CString("Standard mode: Neutral"));
818         myCResultDialog.SetText(text);
819         SetTitle(CString("Standard mode: Neutral"));
820 }
821
822 // Change the color of faces on a user cylinder
823 void CViewer3dDoc::OnUsercylinderChangefacecolor() 
824 {
825         myAISContext->OpenLocalContext();
826         myAISContext->Activate(myAISContext->Current(),4);
827         myState = FACE_COLOR;
828 // see the following of treatment in inputevent
829 }
830
831 // Make 3d fillets on solids
832 // It is necessary to activate the edges selection mode and select edges on an object
833 // before running this function
834 void CViewer3dDoc::OnFillet3d() 
835 {
836     if( !myAISContext->HasOpenedContext())
837     {
838         AfxMessageBox("It is necessary to activate the edges selection mode\n\
839 and select edges on an object before \nrunning this function");
840         return;
841     }
842     
843         myAISContext->InitSelected();
844         if (myAISContext->MoreSelected()) {     
845                         Handle(AIS_Shape) S = Handle(AIS_Shape)::DownCast(myAISContext->SelectedInteractive());
846                         
847                         if (S.IsNull()){
848                                 AfxMessageBox("It is necessary to activate the edges selection mode\n\
849 and select edges on an object before \nrunning this function");
850                                 return;
851                         }
852                 
853                         TopoDS_Shape Sh=S->Shape();
854         
855                         BRepFilletAPI_MakeFillet aFillet(Sh);
856                                 
857                         for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())                                                          
858                         {
859                 TopoDS_Edge anEdge;
860                                 try {
861                                         anEdge=TopoDS::Edge(myAISContext->SelectedShape());
862                                 }
863                     catch(Standard_Failure)
864                         {
865                                 }
866                                 
867                                 if (anEdge.IsNull())
868                 {
869                     AfxMessageBox("It is necessary to activate the edges selection mode\n\
870 and select edges on an object before \nrunning this function");
871                     return;
872                 }
873                         }
874
875                         BoxRadius dlg(NULL,10.);
876                         if (dlg.DoModal() == IDOK){
877                                 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected()){
878                 TopoDS_Edge anEdge = TopoDS::Edge(myAISContext->SelectedShape());
879                                 aFillet.Add(dlg.m_radius,anEdge);
880                                 }
881                         }
882                         else return;
883
884             TopoDS_Shape aNewShape;
885 //            if(!aFillet.IsDone())
886             try{
887                aNewShape = aFillet.Shape();
888             }
889             catch(Standard_Failure)
890             {
891                AfxMessageBox("Error During Fillet computation");
892                return;
893             }
894             S ->Set(aNewShape);
895                         myAISContext->Redisplay(S);                                             
896                         
897         }
898 TCollection_AsciiString Message ("\
899 Handle(AIS_Shape) S = Handle(AIS_Shape)::DownCast(myAISContext->Interactive());  \n\
900 \n\
901 BRepAPI_MakeFillet aFillet(S->Shape());   \n\
902 \n\
903 TopoDS_Edge anEdge=TopoDS::Edge(myAISContext->SelectedShape());  \n\
904 \n\
905 aFillet.Add(dlg.m_radius,anEdge);  \n\
906 \n\
907 TopoDS_Shape aNewShape = aFillet.Shape();  \n\
908 \n\
909 S ->Set(aNewShape);  \n\
910 \n\
911 myAISContext->Redisplay(S);  \n\
912 \n");
913
914         CString text(Message.ToCString());
915         myCResultDialog.SetTitle(CString("Make a fillet"));
916         myCResultDialog.SetText(text);
917         SetTitle(CString("Make a fillet"));
918 }
919 // Create and display a circle with standard tools
920 void CViewer3dDoc::OnCircle() 
921 {
922         gp_Ax2 ax2(gp_Pnt(0., 0., 0.), gp_Dir(0., 0., -1.));
923         Handle(Geom_Circle) C = new Geom_Circle(ax2, 300);
924 //      GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.));
925 //      Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value());
926         Handle(AIS_Circle) anAISCirc = new AIS_Circle(C);
927         myAISContext->Display(anAISCirc);
928
929 TCollection_AsciiString Message ("\
930 GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.));  \n\
931 \n\
932 Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value());  \n\
933 \n\
934 myAISContext->Display(anAISCirc);  \n\
935 \n");
936
937         CString text(Message.ToCString());
938         myCResultDialog.SetTitle(CString("Create a circle"));
939         myCResultDialog.SetText(text);
940         SetTitle(CString("Create a circle"));
941 }
942
943 void CViewer3dDoc::OnLine() 
944 {
945         // TODO: Add your command handler code here
946         gp_Lin L(gp_Pnt(0.,0.,0.),gp_Dir(1.,0.,0.));
947         Handle(Geom_Line) aLine = new Geom_Line(L);
948         Handle(AIS_Line) anAISLine = new AIS_Line(aLine);
949         myAISContext->Display(anAISLine);       
950
951 TCollection_AsciiString Message ("\
952 gp_Lin L(gp_Pnt(0.,0.,0.),gp_Dir(1.,0.,0.));  \n\
953 \n\
954 Handle(Geom_Line) aLine = new Geom_Line(L);  \n\
955 \n\
956 Handle(AIS_Line) anAISLine = new AIS_Line(aLine); \n\
957 \n\
958 myAISContext->Display(anAISLine);  \n\
959 \n");
960
961         CString text(Message.ToCString());
962         myCResultDialog.SetTitle(CString("Create a line"));
963         myCResultDialog.SetText(text);
964         SetTitle(CString("Create a line"));
965 }
966
967 void CViewer3dDoc::OnNbisos() 
968 {
969         int nu = myAISContext->DefaultDrawer()->UIsoAspect()->Number();
970         int nv = myAISContext->DefaultDrawer()->VIsoAspect()->Number();
971         DlgIsos dlg(NULL,nu,nv);
972         if (dlg.DoModal() == IDOK) {
973                 myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(dlg.m_isou);
974                 myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(dlg.m_isov);
975
976 TCollection_AsciiString Message ("\
977 myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(dlg.m_isou);  \n\
978 \n\
979 myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(dlg.m_isov);  \n\
980 \n");
981
982         CString text(Message.ToCString());
983         myCResultDialog.SetTitle(CString("Iso Aspect"));
984         myCResultDialog.SetText(text);
985         SetTitle(CString("Iso Aspect"));
986
987         }
988 }
989
990 BOOL CViewer3dDoc::OnNewDocument()
991 {
992         if (!CDocument::OnNewDocument())
993                 return FALSE;
994
995         // TODO: add reinitialization code here
996         // (SDI documents will reuse this document)
997   SetTitle(myPresentation->GetName());
998
999   myAISContext->EraseAll(Standard_False);
1000   myAISContext->SetDisplayMode(AIS_Shaded);
1001
1002   POSITION pos = GetFirstViewPosition();
1003   while (pos != NULL)
1004   {
1005     CViewer3dView* pView = (CViewer3dView*) GetNextView(pos);
1006     pView->Reset();
1007   }  
1008
1009         return TRUE;
1010 }
1011
1012 void CViewer3dDoc::OnFileNew()
1013 {
1014   OnNewDocument();
1015 }
1016
1017 void CViewer3dDoc::InitViewButtons()
1018 {
1019   POSITION pos = GetFirstViewPosition();
1020   while (pos != NULL)
1021   {
1022     CViewer3dView* pView = (CViewer3dView*) GetNextView(pos);
1023     pView->InitButtons();
1024   }
1025 }
1026
1027 void CViewer3dDoc::OnTextureOn()
1028 {
1029         isTextureSampleStarted = TRUE;
1030         Start();
1031 }
1032
1033 void CViewer3dDoc::DoSample()
1034 {
1035   InitViewButtons();
1036
1037   HCURSOR hOldCursor = ::GetCursor();
1038   HCURSOR hNewCursor = AfxGetApp()->LoadStandardCursor(IDC_APPSTARTING);
1039
1040   SetCursor(hNewCursor);
1041   {
1042     try
1043     {
1044       myPresentation->DoSample();
1045     }
1046     catch (Standard_Failure)
1047     {
1048       Standard_SStream aSStream;
1049       aSStream << "An exception was caught: " << Standard_Failure::Caught() << ends;
1050       Standard_CString aMsg = aSStream.str().c_str();
1051 //      aSStream.rdbuf()->freeze(0);   // allow deletion of dynamic array
1052       AfxMessageBox (aMsg);
1053     }
1054   }
1055   SetCursor(hOldCursor);
1056 }
1057
1058 void CViewer3dDoc::OnBUTTONStart() 
1059 {
1060   myAISContext->EraseAll(Standard_False);
1061   myPresentation->FirstSample();
1062   DoSample();
1063 }
1064
1065 void CViewer3dDoc::OnBUTTONEnd()
1066 {
1067   myAISContext->EraseAll(Standard_False);
1068   myPresentation->LastSample();
1069   DoSample();
1070 }
1071
1072 void CViewer3dDoc::OnBUTTONRepeat() 
1073 {
1074   DoSample();
1075 }
1076
1077 void CViewer3dDoc::OnBUTTONNext() 
1078 {
1079   if (!myPresentation->AtLastSample())
1080   {
1081     myPresentation->NextSample();
1082     DoSample();
1083   }
1084 }
1085
1086 void CViewer3dDoc::OnBUTTONPrev() 
1087 {
1088   if (!myPresentation->AtFirstSample())
1089   {
1090     myPresentation->PrevSample();
1091     DoSample();
1092   }
1093 }
1094
1095 void CViewer3dDoc::OnUpdateBUTTONNext(CCmdUI* pCmdUI) 
1096 {
1097         if ( isTextureSampleStarted )
1098                 pCmdUI->Enable (!myPresentation->AtLastSample());
1099         else
1100                 pCmdUI->Enable (FALSE);
1101 }
1102
1103 void CViewer3dDoc::OnUpdateBUTTONPrev(CCmdUI* pCmdUI) 
1104 {
1105         if ( isTextureSampleStarted )
1106                 pCmdUI->Enable (!myPresentation->AtFirstSample());
1107         else
1108                 pCmdUI->Enable (FALSE);
1109 }
1110
1111 void CViewer3dDoc::OnUpdateBUTTONStart(CCmdUI* pCmdUI) 
1112 {
1113         pCmdUI->Enable (isTextureSampleStarted);
1114 }
1115
1116 void CViewer3dDoc::OnUpdateBUTTONRepeat(CCmdUI* pCmdUI) 
1117 {
1118         pCmdUI->Enable (isTextureSampleStarted);
1119 }
1120
1121 void CViewer3dDoc::OnUpdateBUTTONEnd(CCmdUI* pCmdUI) 
1122 {
1123         pCmdUI->Enable (isTextureSampleStarted);
1124 }
1125
1126 void CViewer3dDoc::OnDumpView() 
1127 {
1128   // save current directory and restore it on exit
1129   char aCurPath[MAX_PATH];
1130   ::GetCurrentDirectory(MAX_PATH, aCurPath);
1131
1132   ::SetCurrentDirectory(myLastPath);
1133
1134   CFileDialog *aDlg = new CFileDialog(false, "gif", "OCCView.gif", 
1135     OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "GIF Files (*.gif)|*.gif||", NULL);
1136
1137   int result = aDlg->DoModal();
1138   if ( result == IDOK) 
1139   {
1140     CString aFileName = aDlg->GetFileName();
1141     delete aDlg;
1142
1143     POSITION pos = GetFirstViewPosition();
1144     while (pos != NULL)
1145     {
1146       CViewer3dView* pView = (CViewer3dView*) GetNextView(pos);
1147       pView->UpdateWindow();
1148     }       
1149
1150     myViewer->InitActiveViews();
1151     Handle(V3d_View) aView = myViewer->ActiveView();
1152     char aStrFileName[MAX_PATH];
1153     strcpy_s(aStrFileName, aFileName);
1154     aView->Dump(aStrFileName);
1155   }
1156   else 
1157     delete aDlg;
1158   
1159   ::GetCurrentDirectory(MAX_PATH, myLastPath);
1160   ::SetCurrentDirectory(aCurPath);
1161 }
1162
1163 void CViewer3dDoc::Start()
1164 {
1165   myPresentation->Init();
1166   OnBUTTONStart();
1167 }
1168
1169 void CViewer3dDoc::Fit()
1170 {
1171         CMDIFrameWnd *pFrame =  (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
1172         CMDIChildWnd *pChild =  (CMDIChildWnd *) pFrame->GetActiveFrame();
1173         CViewer3dView *pView = (CViewer3dView *) pChild->GetActiveView();
1174         pView->FitAll();
1175 }