0024002: Overall code and build procedure refactoring - samples
[occt.git] / samples / mfc / standard / 04_Viewer3d / src / Viewer3dDoc.cpp
CommitLineData
7fd59977 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
21IMPLEMENT_DYNCREATE(CViewer3dDoc, CDocument)
22
47162471 23BEGIN_MESSAGE_MAP(CViewer3dDoc, OCC_3dDoc)
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
7fd59977 74END_MESSAGE_MAP()
75
76/////////////////////////////////////////////////////////////////////////////
77// CViewer3dDoc construction/destruction
78
79CViewer3dDoc::CViewer3dDoc()
a6eb515f 80:OCC_3dDoc()
7fd59977 81{
47162471 82 myCylinder.Nullify();
83 mySphere.Nullify();
84 myBox.Nullify();
85 myOverlappedCylinder.Nullify();
86 myOverlappedSphere.Nullify();
87 myOverlappedBox.Nullify();
88 myOffsetDlg = NULL;
89 myStaticTrihedronAxisIsDisplayed = FALSE;
90 myState = -1;
7fd59977 91
47162471 92 isTextureSampleStarted = FALSE;
7fd59977 93
47162471 94 myPresentation = OCCDemo_Presentation::Current;
95 myPresentation->SetDocument(this);
7fd59977 96
97
47162471 98 myAISContext->DefaultDrawer()->ShadingAspect()->SetColor(Quantity_NOC_CHARTREUSE1);
99 myAISContext->DefaultDrawer()->ShadingAspect()->SetMaterial(Graphic3d_NOM_SILVER);
7fd59977 100
47162471 101 strcpy_s(myDataDir, "Data");
102 strcpy_s(myLastPath, ".");
7fd59977 103
47162471 104 /*
105 Handle(AIS_Trihedron) myTrihedron;
106 Handle(Geom_Axis2Placement) myTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
107 myTrihedron=new AIS_Trihedron(myTrihedronAxis);
108 myAISContext->Display(myTrihedron);
109 */
7fd59977 110}
111
112CViewer3dDoc::~CViewer3dDoc()
113{
114}
115
116/////////////////////////////////////////////////////////////////////////////
117// CViewer3dDoc diagnostics
118
119#ifdef _DEBUG
120void CViewer3dDoc::AssertValid() const
121{
47162471 122 CDocument::AssertValid();
7fd59977 123}
124
125void CViewer3dDoc::Dump(CDumpContext& dc) const
126{
47162471 127 CDocument::Dump(dc);
7fd59977 128}
129#endif //_DEBUG
130
131/////////////////////////////////////////////////////////////////////////////
132// CViewer3dDoc commands
133
576f8b11 134void CViewer3dDoc::UpdateResultMessageDlg (CString theTitle, const TCollection_AsciiString& theMessage)
7fd59977 135{
47162471 136 CString aText (theMessage.ToCString());
137 myCResultDialog.SetText (aText);
138 myCResultDialog.SetTitle(theTitle);
576f8b11 139}
7fd59977 140
576f8b11 141void CViewer3dDoc::UpdateResultMessageDlg(CString theTitle, CString theMessage)
142{
143 myCResultDialog.SetText (theMessage);
144 myCResultDialog.SetTitle(theTitle);
7fd59977 145}
146
47162471 147void CViewer3dDoc::OnBox()
7fd59977 148{
47162471 149 if(myBox.IsNull())
150 {
151 BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);
7fd59977 152
153
47162471 154 myBox = new AIS_Shape(B.Shape());
7fd59977 155
47162471 156 myAISContext->SetMaterial(myBox,Graphic3d_NOM_PEWTER);
157 myAISContext->SetDisplayMode(myBox,1);
7fd59977 158
47162471 159 myAISContext->Display(myBox);
160 TCollection_AsciiString Message("\
7fd59977 161BRepPrimAPI_MakeBox Box1(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
47162471 162 ");
7fd59977 163
47162471 164 UpdateResultMessageDlg("Create Box",Message);
165 }
7fd59977 166}
167
47162471 168void CViewer3dDoc::OnCylinder()
7fd59977 169{
47162471 170 if(myCylinder.IsNull())
171 {
172 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
173 myCylinder = new User_Cylinder(CylAx2, 80.,200.);
7fd59977 174
47162471 175 myAISContext->SetDisplayMode(myCylinder,1);
7fd59977 176
47162471 177 myAISContext->Display(myCylinder);
7fd59977 178
47162471 179 TCollection_AsciiString Message("\
7fd59977 180gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));\n\
181C = new User_Cylinder(CylAx2, 80.,200.);;\n\
47162471 182 ");
7fd59977 183
47162471 184 UpdateResultMessageDlg("Create Cylinder",Message);
185 }
7fd59977 186}
187
47162471 188void CViewer3dDoc::OnSphere()
7fd59977 189{
47162471 190 if(mySphere.IsNull())
191 {
192 BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);
7fd59977 193
47162471 194 mySphere = new AIS_Shape(S.Shape());
7fd59977 195
47162471 196 myAISContext->SetMaterial(mySphere,Graphic3d_NOM_BRONZE);
197 myAISContext->SetDisplayMode(mySphere,1);
198
199 myAISContext->Display(mySphere);
200 TCollection_AsciiString Message("\
7fd59977 201BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);\n\
47162471 202 ");
203 UpdateResultMessageDlg("Create Sphere",Message);
204 }
7fd59977 205}
206
47162471 207void CViewer3dDoc::OnRemoveAll()
7fd59977 208
209{
47162471 210 AIS_ListOfInteractive aListOfObjects;
211 myAISContext->ObjectsInside(aListOfObjects,AIS_KOI_Shape);
7fd59977 212
47162471 213 AIS_ListIteratorOfListOfInteractive aListIterator;
214 for(aListIterator.Initialize(aListOfObjects);aListIterator.More();aListIterator.Next()){
215 myAISContext->Remove(aListIterator.Value());
216 }
7fd59977 217
47162471 218 myAISContext->Remove(myCylinder);
7fd59977 219
220
47162471 221 myCylinder.Nullify();
222 mySphere.Nullify();
223 myBox.Nullify();
224 myOverlappedCylinder.Nullify();
225 myOverlappedSphere.Nullify();
226 myOverlappedBox.Nullify();
227 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
228 myOffsetDlg->UpdateValues();
7fd59977 229}
230
231void CViewer3dDoc::OnOverlappedBox()
232{
47162471 233 OnBox();
234 if(myOverlappedBox.IsNull()){
235 BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);
7fd59977 236
47162471 237 BRepBuilderAPI_NurbsConvert aNurbsConvert(B.Shape());
238 TopoDS_Shape aBoxShape2 = aNurbsConvert.Shape();
7fd59977 239
240
47162471 241 myOverlappedBox = new AIS_Shape(aBoxShape2);
7fd59977 242
47162471 243 myAISContext->SetMaterial(myOverlappedBox,Graphic3d_NOM_GOLD);
244 myAISContext->SetDisplayMode(myOverlappedBox,1);
7fd59977 245
47162471 246 myAISContext->Display(myOverlappedBox);
247 TCollection_AsciiString Message("\
7fd59977 248BRepPrimAPI_MakeBox Box1(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
249\n\
250BRepPrimAPI_MakeBox Box2(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
251BRepBuilderAPI_NurbsConvert aNurbsConvert(Box2.Shape());\n\
47162471 252 ");
253 UpdateResultMessageDlg("Create overlapped boxes",Message);
254 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
255 myOffsetDlg->UpdateValues();
256 }
7fd59977 257}
258
47162471 259void CViewer3dDoc::OnOverlappedCylinder()
7fd59977 260{
47162471 261 OnCylinder();
262
263 if(myOverlappedCylinder.IsNull()){
264 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
265 BRepPrimAPI_MakeCylinder C(CylAx2, 80.,200.);
7fd59977 266
47162471 267 BRepBuilderAPI_NurbsConvert aNurbsConvert(C.Shape());
268 TopoDS_Shape aCylShape2 = aNurbsConvert.Shape();
7fd59977 269
47162471 270 myOverlappedCylinder = new AIS_Shape(aCylShape2);
7fd59977 271
7fd59977 272
47162471 273 myAISContext->SetMaterial(myOverlappedCylinder,Graphic3d_NOM_GOLD);
274 myAISContext->SetDisplayMode(myOverlappedCylinder,1);
7fd59977 275
47162471 276 myAISContext->Display(myOverlappedCylinder);
7fd59977 277
47162471 278 TCollection_AsciiString Message("\
7fd59977 279gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));\n\
280Cylinder1 = new User_Cylinder(CylAx2, 80.,200.);\n\
281\n\
282BRepPrimAPI_MakeCylinder Cylinder2(CylAx2, 80.,200.);\n\
283BRepBuilderAPI_NurbsConvert aNurbsConvert(Cylinder2.Shape());\n\
47162471 284 ");
285 UpdateResultMessageDlg("Create overlapped cylinders",Message);
286 if (myOffsetDlg && myOffsetDlg->IsWindowVisible())
287 {
288 myOffsetDlg->UpdateValues();
289 }
290 }
7fd59977 291}
292
47162471 293void CViewer3dDoc::OnOverlappedSphere()
7fd59977 294{
47162471 295 OnSphere();
296 if(myOverlappedSphere.IsNull()){
297 BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);
7fd59977 298
47162471 299 BRepBuilderAPI_NurbsConvert aNurbsConvert(S.Shape());
300 TopoDS_Shape aSphereShape2 = aNurbsConvert.Shape();
7fd59977 301
47162471 302 myOverlappedSphere = new AIS_Shape(aSphereShape2);
7fd59977 303
47162471 304 myAISContext->SetMaterial(myOverlappedSphere,Graphic3d_NOM_GOLD);
7fd59977 305
47162471 306 myAISContext->SetDisplayMode(myOverlappedSphere,1);
7fd59977 307
47162471 308 myAISContext->Display(myOverlappedSphere);
7fd59977 309
47162471 310 TCollection_AsciiString Message("\
7fd59977 311BRepPrimAPI_MakeSphere Sphere1(gp_Pnt(0,300,0), 100.);\n\
312\n\
313BRepPrimAPI_MakeSphere Sphere2(gp_Pnt(0,300,0), 100.);\n\
314BRepBuilderAPI_NurbsConvert aNurbsConvert(Sphere2.Shape());\n\
47162471 315 ");
316 UpdateResultMessageDlg("Create overlapped spheres",Message);
317 if (myOffsetDlg && myOffsetDlg->IsWindowVisible())
318 {
319 myOffsetDlg->UpdateValues();
320 }
321 }
7fd59977 322}
323
47162471 324void CViewer3dDoc::OnPolygonOffsets()
7fd59977 325{
47162471 326 myOffsetDlg = new COffsetDlg(this);
327 myOffsetDlg->Create(COffsetDlg::IDD,NULL);
328 myAISContext->UpdateCurrentViewer();
7fd59977 329}
330
331void CViewer3dDoc::OnUpdatePolygonOffsets(CCmdUI* pCmdUI)
332{
47162471 333 Standard_Integer aOffsetMode;
334 Standard_ShortReal aFactor;
335 Standard_ShortReal aCylUnits = 0;
336 Standard_ShortReal aSphereUnits = 0;
337 Standard_ShortReal aBoxUnits = 0;
7fd59977 338
47162471 339 BOOL IsOverlappedCylinderDisplayed = myAISContext->IsDisplayed(myOverlappedCylinder);
340 BOOL IsOverlappedSphereDisplayed = myAISContext->IsDisplayed(myOverlappedSphere);
341 BOOL IsOverlappedBoxDisplayed = myAISContext->IsDisplayed(myOverlappedBox);
342 BOOL IsAnyOverlappedObjectDisplayed =
343 IsOverlappedCylinderDisplayed || IsOverlappedSphereDisplayed || IsOverlappedBoxDisplayed;
7fd59977 344
47162471 345 if(!myOverlappedCylinder.IsNull() && IsOverlappedCylinderDisplayed){
346 myOverlappedCylinder->PolygonOffsets(aOffsetMode,aFactor,aCylUnits);
347 }
7fd59977 348
47162471 349 if(!myOverlappedSphere.IsNull() && IsOverlappedSphereDisplayed){
350 myOverlappedSphere->PolygonOffsets(aOffsetMode,aFactor,aSphereUnits);
351 }
352
353 if(!myOverlappedBox.IsNull() && IsOverlappedBoxDisplayed){
354 myOverlappedBox->PolygonOffsets(aOffsetMode,aFactor,aBoxUnits);
355 }
356
357 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
358 pCmdUI->SetCheck(TRUE);
359 else
360 pCmdUI->SetCheck(FALSE);
361 if (IsAnyOverlappedObjectDisplayed)
362 if(myOffsetDlg)
363 pCmdUI->Enable(!myOffsetDlg->IsWindowVisible());
364 else
365 pCmdUI->Enable(TRUE);
366 else
367 pCmdUI->Enable(FALSE);
7fd59977 368}
369
47162471 370void CViewer3dDoc::OnUpdateCylinder(CCmdUI* pCmdUI)
7fd59977 371{
47162471 372 pCmdUI->Enable(myCylinder.IsNull());
7fd59977 373}
374
47162471 375void CViewer3dDoc::OnUpdateSphere(CCmdUI* pCmdUI)
7fd59977 376{
47162471 377 pCmdUI->Enable(mySphere.IsNull());
7fd59977 378}
379
47162471 380void CViewer3dDoc::OnUpdateBox(CCmdUI* pCmdUI)
7fd59977 381{
47162471 382 pCmdUI->Enable(myBox.IsNull());
7fd59977 383}
384
47162471 385void CViewer3dDoc::OnUpdateOverlappedCylinder(CCmdUI* pCmdUI)
7fd59977 386{
47162471 387 pCmdUI->Enable (myOverlappedCylinder.IsNull()
388 || myCylinder.IsNull());
389
7fd59977 390}
391
47162471 392void CViewer3dDoc::OnUpdateOverlappedSphere(CCmdUI* pCmdUI)
7fd59977 393{
47162471 394 pCmdUI->Enable (myOverlappedSphere.IsNull()
395 || mySphere.IsNull());
7fd59977 396}
397
47162471 398void CViewer3dDoc::OnUpdateOverlappedBox(CCmdUI* pCmdUI)
7fd59977 399{
47162471 400 pCmdUI->Enable (myOverlappedBox.IsNull()
401 || myBox.IsNull());
7fd59977 402}
403
47162471 404void CViewer3dDoc::OnObjectRemove()
7fd59977 405{
47162471 406 if(myAISContext->IsCurrent(myBox))
407 myBox.Nullify();
7fd59977 408
47162471 409 if(myAISContext->IsCurrent(myCylinder))
410 myCylinder.Nullify();
7fd59977 411
47162471 412 if(myAISContext->IsCurrent(mySphere))
413 mySphere.Nullify();
7fd59977 414
47162471 415 if(myAISContext->IsCurrent(myOverlappedBox))
416 myOverlappedBox.Nullify();
7fd59977 417
47162471 418 if(myAISContext->IsCurrent(myOverlappedCylinder))
419 myOverlappedCylinder.Nullify();
7fd59977 420
47162471 421 if(myAISContext->IsCurrent(myOverlappedSphere))
422 myOverlappedSphere.Nullify();
7fd59977 423
7fd59977 424
47162471 425 for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->InitCurrent())
426 myAISContext->Remove(myAISContext->Current(),Standard_True);
7fd59977 427
47162471 428 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
429 myOffsetDlg->UpdateValues();
7fd59977 430}
431
47162471 432void CViewer3dDoc::OnObjectErase()
7fd59977 433
434{
47162471 435 OCC_3dBaseDoc::OnObjectErase();
436 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
437 myOffsetDlg->UpdateValues();
7fd59977 438}
439
47162471 440void CViewer3dDoc::OnObjectDisplayall()
7fd59977 441
442{
47162471 443 OCC_3dBaseDoc::OnObjectDisplayall();
444 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
445 myOffsetDlg->UpdateValues();
7fd59977 446}
447
448Handle_User_Cylinder CViewer3dDoc::GetCylinder()
449{
47162471 450 return myCylinder;
7fd59977 451}
452
453
454Handle_AIS_Shape CViewer3dDoc::GetSphere()
455{
47162471 456 return mySphere;
7fd59977 457}
458
459Handle_AIS_Shape CViewer3dDoc::GetBox()
460{
47162471 461 return myBox;
7fd59977 462}
463
464Handle_AIS_Shape CViewer3dDoc::GetOverlappedCylinder()
465{
47162471 466 return myOverlappedCylinder;
7fd59977 467}
468
469
470Handle_AIS_Shape CViewer3dDoc::GetOverlappedSphere()
471{
47162471 472 return myOverlappedSphere;
7fd59977 473}
474
475Handle_AIS_Shape CViewer3dDoc::GetOverlappedBox()
476{
47162471 477 return myOverlappedBox;
7fd59977 478}
479
47162471 480void CViewer3dDoc::DragEvent (const Standard_Integer theX,
481 const Standard_Integer theY,
482 const Standard_Integer theState,
483 const Handle(V3d_View)& theView)
7fd59977 484{
47162471 485 OCC_3dBaseDoc::DragEvent (theX, theY, theState, theView);
486 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
487 myOffsetDlg->UpdateValues();
7fd59977 488}
489
490//-----------------------------------------------------------------------------------------
491//
492//-----------------------------------------------------------------------------------------
5c573e69 493void CViewer3dDoc::InputEvent(const Standard_Integer /*x*/,
494 const Standard_Integer /*y*/,
495 const Handle(V3d_View)& /*aView*/ )
7fd59977 496{
5c1f974e 497 if (myOffsetDlg && myOffsetDlg->IsWindowVisible())
498 myOffsetDlg->UpdateValues();
7fd59977 499
5c1f974e 500 Quantity_Color CSFColor;
501 COLORREF MSColor;
502 myAISContext->Select();
7fd59977 503
5c1f974e 504 // Change the color of a selected face in a user cylinder
505 if (myState == FACE_COLOR)
506 {
507 myAISContext->InitSelected();
508 if (myAISContext->MoreSelected())
509 {
510 Handle_AIS_InteractiveObject Current = myAISContext->SelectedInteractive();
511 if (Current->HasColor())
512 {
513 CSFColor = myAISContext->Color (Current);
514 MSColor = RGB (CSFColor.Red()*255.0, CSFColor.Green()*255.0, CSFColor.Blue()*255.0);
515 }
516 else
517 {
518 MSColor = RGB (255, 255, 255);
519 }
520
521 CColorDialog dlgColor(MSColor);
522 if (dlgColor.DoModal() == IDOK)
523 {
524 MSColor = dlgColor.GetColor();
525 CSFColor = Quantity_Color (GetRValue (MSColor)/255.0,
526 GetGValue (MSColor)/255.0,
527 GetBValue (MSColor)/255.0,
528 Quantity_TOC_RGB);
529
530 TopoDS_Shape S = myAISContext->SelectedShape();
531 Handle(Geom_Surface) Surface = BRep_Tool::Surface (TopoDS::Face(S));
532 if (Surface->IsKind (STANDARD_TYPE (Geom_Plane)))
533 {
534 Handle(User_Cylinder)::DownCast (myAISContext->SelectedInteractive())
535 ->SetPlanarFaceColor (CSFColor.Name());
536 }
537 else
538 {
539 Handle(User_Cylinder)::DownCast (myAISContext->SelectedInteractive())
540 ->SetCylindricalFaceColor (CSFColor.Name());
541 }
542
543 myAISContext->Redisplay (myAISContext->SelectedInteractive());
544 myState = -1;
545 myAISContext->CloseLocalContext();
546 }
547 }
548
5c573e69 549 myCResultDialog.SetTitle("Change face color");
550 myCResultDialog.SetText(" TopoDS_Shape S = myAISContext->SelectedShape(); \n"
5c1f974e 551 " \n"
552 " Handle(Geom_Surface) Surface = BRep_Tool::Surface(TopoDS::Face(S));"
553 " if (Surface->IsKind(STANDARD_TYPE(Geom_Plane))) \n"
554 " Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetPlanarFaceColor(CSFColor.Name()); \n"
555 " else \n"
556 " Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetCylindricalFaceColor(CSFColor.Name()); \n"
557 " \n"
558 " myAISContext->Redisplay(myAISContext->Current()); \n"
559 " \n"
560 " myAISContext->CloseLocalContext(); \n"
561 " \n"
562 " \n"
563 " NOTE: a User_Cylinder is an object defined by the user. \n"
564 " The User_Cylinder class inherit from the AIS_InteractiveObject \n"
565 " Cascade class, it's use is the same as an AIS_InteractiveObject. \n"
566 " Methods SetPlanarFaceColor and SetCylindricalFaceColor are also \n"
567 " defined in the User_Cylinder class. \n"
568 " \n");
576f8b11 569 SetTitle (L"Change face color");
5c1f974e 570 }
571}
7fd59977 572
573//-----------------------------------------------------------------------------------------
574//
575//-----------------------------------------------------------------------------------------
47162471 576void CViewer3dDoc::ShiftDragEvent (const Standard_Integer theX,
577 const Standard_Integer theY,
578 const Standard_Integer theState,
579 const Handle(V3d_View)& theView)
7fd59977 580{
47162471 581 OCC_3dBaseDoc::ShiftDragEvent(theX, theY, theState, theView);
5c1f974e 582 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
583 myOffsetDlg->UpdateValues();
7fd59977 584}
585
586
587//-----------------------------------------------------------------------------------------
588//
589//-----------------------------------------------------------------------------------------
47162471 590void CViewer3dDoc::ShiftInputEvent (const Standard_Integer theX,
591 const Standard_Integer theY,
592 const Handle(V3d_View)& theView)
7fd59977 593{
47162471 594 OCC_3dBaseDoc::ShiftInputEvent (theX, theY, theView);
5c1f974e 595 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
596 myOffsetDlg->UpdateValues();
7fd59977 597}
598
47162471 599void CViewer3dDoc::OnObjectColoredMesh()
7fd59977 600{
601 for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->NextCurrent())
5c1f974e 602 if (myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
603 {
604 myAISContext->ClearPrs(myAISContext->Current(),6,Standard_False);
605 myAISContext->RecomputePrsOnly(myAISContext->Current(),Standard_False);
606 myAISContext->SetDisplayMode(myAISContext->Current(),6);
607 }
7fd59977 608}
609
47162471 610void CViewer3dDoc::OnUpdateObjectColoredMesh(CCmdUI* pCmdUI)
7fd59977 611{
612 bool CylinderIsCurrentAndDisplayed = false;
613 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
47162471 614 if(myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
615 CylinderIsCurrentAndDisplayed=true;
616 pCmdUI->Enable (CylinderIsCurrentAndDisplayed);
7fd59977 617}
618
47162471 619void CViewer3dDoc::OnUpdateObjectWireframe(CCmdUI* pCmdUI)
7fd59977 620{
621 bool OneOrMoreInShadingOrColoredMesh = false;
622 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
623 if (myAISContext->IsDisplayed(myAISContext->Current(),1) || myAISContext->IsDisplayed(myAISContext->Current(),6))
47162471 624 OneOrMoreInShadingOrColoredMesh=true;
625 pCmdUI->Enable (OneOrMoreInShadingOrColoredMesh);
7fd59977 626}
627
628
47162471 629void CViewer3dDoc::OnUpdateObjectShading(CCmdUI* pCmdUI)
7fd59977 630{
631 bool OneOrMoreInWireframeOrColoredMesh = false;
632 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
633 if (myAISContext->IsDisplayed(myAISContext->Current(),0) || myAISContext->IsDisplayed(myAISContext->Current(),6))
47162471 634 OneOrMoreInWireframeOrColoredMesh=true;
635 pCmdUI->Enable (OneOrMoreInWireframeOrColoredMesh);
7fd59977 636}
637
47162471 638void CViewer3dDoc::OnOptionsTrihedronDynamicTrihedron()
7fd59977 639{
47162471 640 if (myAISContext -> IsDisplayed(myTrihedron))
641 {
642 myAISContext->Remove(myTrihedron);
643 }
644 else
645 {
646 Handle(Geom_Axis2Placement) myTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
647 myTrihedron=new AIS_Trihedron(myTrihedronAxis);
648 myAISContext->SetTrihedronSize(200, Standard_True);
649 myAISContext->Display(myTrihedron);
650 }
7fd59977 651}
652
47162471 653void CViewer3dDoc::OnUpdateOptionsTrihedronDynamicTrihedron(CCmdUI* pCmdUI)
7fd59977 654{
47162471 655 if (myAISContext->IsDisplayed(myTrihedron))
656 pCmdUI->SetCheck(1);
657 else
658 pCmdUI->SetCheck(0);
7fd59977 659}
660
661void CViewer3dDoc::SetMyStaticTrihedronAxisIsDisplayed(BOOL IsDisplayed)
662{
47162471 663 myStaticTrihedronAxisIsDisplayed = IsDisplayed;
7fd59977 664}
665
666void CViewer3dDoc::OnUpdateOptionsTrihedronStaticTrihedron(CCmdUI* pCmdUI)
667{
47162471 668 if (myStaticTrihedronAxisIsDisplayed)
669 pCmdUI->SetCheck(1);
670 else
671 pCmdUI->SetCheck(0);
672
7fd59977 673}
674
a6eb515f 675void CViewer3dDoc::Popup (const Standard_Integer x,
676 const Standard_Integer y ,
677 const Handle(V3d_View)& aView)
7fd59977 678{
a6eb515f 679 myPopupMenuNumber=0;
680 // Specified check for context menu number to call
681 myAISContext->InitCurrent();
682 if (myAISContext->MoreCurrent())
7fd59977 683 {
a6eb515f 684 if (myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
685 {
686 myPopupMenuNumber = 2;
687 //return;
688 }
689 }
690 OCC_3dBaseDoc::Popup(x,y, aView);
7fd59977 691}
5c1f974e 692
7fd59977 693//Set faces selection mode
694void CViewer3dDoc::OnFaces()
695{
5c1f974e 696 myAISContext->CloseAllContexts();
697 myAISContext->OpenLocalContext();
698 myAISContext->ActivateStandardMode (TopAbs_FACE);
7fd59977 699
5c573e69 700 myCResultDialog.SetTitle("Standard mode: TopAbs_FACE");
701 myCResultDialog.SetText(" myAISContext->OpenLocalContext(); \n"
5c1f974e 702 " \n"
703 " myAISContext->ActivateStandardMode(TopAbs_FACE); \n"
704 " \n");
576f8b11 705 SetTitle (L"Standard mode: TopAbs_FACE");
7fd59977 706}
707
708//Set edges selection mode
709void CViewer3dDoc::OnEdges()
710{
5c1f974e 711 myAISContext->CloseAllContexts();
712 myAISContext->OpenLocalContext();
713 myAISContext->ActivateStandardMode(TopAbs_EDGE);
7fd59977 714
5c573e69 715 myCResultDialog.SetTitle("Standard mode: TopAbs_EDGE");
716 myCResultDialog.SetText(" myAISContext->OpenLocalContext(); \n"
5c1f974e 717 " \n"
718 " myAISContext->ActivateStandardMode(TopAbs_EDGE); \n"
719 " \n");
576f8b11 720 SetTitle (L"Standard mode: TopAbs_EDGE");
7fd59977 721}
722
723// Set vertices selection mode
724void CViewer3dDoc::OnVertices()
725{
5c1f974e 726 myAISContext->CloseAllContexts();
727 myAISContext->OpenLocalContext();
728 myAISContext->ActivateStandardMode (TopAbs_VERTEX);
7fd59977 729
5c573e69 730 myCResultDialog.SetTitle("Standard mode: TopAbs_VERTEX");
731 myCResultDialog.SetText(" myAISContext->OpenLocalContext(); \n"
5c1f974e 732 " \n"
733 " myAISContext->ActivateStandardMode(TopAbs_VERTEX); \n"
734 " \n");
576f8b11 735 SetTitle (L"Standard mode: TopAbs_VERTEX");
7fd59977 736}
737
738//Neutral selection mode
739void CViewer3dDoc::OnNeutral()
740{
5c1f974e 741 myAISContext->CloseAllContexts();
7fd59977 742
5c573e69 743 myCResultDialog.SetTitle("Standard mode: Neutral");
744 myCResultDialog.SetText(" myAISContext->CloseAllContexts(); \n"
5c1f974e 745 " \n");
576f8b11 746 SetTitle (L"Standard mode: Neutral");
7fd59977 747}
748
749// Change the color of faces on a user cylinder
750void CViewer3dDoc::OnUsercylinderChangefacecolor()
751{
5c1f974e 752 myAISContext->OpenLocalContext();
753 myAISContext->Activate(myAISContext->Current(),4);
754 myState = FACE_COLOR;
755 // see the following of treatment in inputevent
7fd59977 756}
757
758// Make 3d fillets on solids
759// It is necessary to activate the edges selection mode and select edges on an object
760// before running this function
761void CViewer3dDoc::OnFillet3d()
762{
5c1f974e 763 if (!myAISContext->HasOpenedContext())
764 {
576f8b11 765 AfxMessageBox (L"It is necessary to activate the edges selection mode\n"
766 L"and select edges on an object before \nrunning this function");
5c1f974e 767 return;
768 }
769
770 myAISContext->InitSelected();
771 if (myAISContext->MoreSelected())
772 {
47162471 773 const Handle(AIS_Shape)& aSelInteractive = Handle(AIS_Shape)::DownCast (myAISContext->SelectedInteractive());
774 if (aSelInteractive.IsNull())
5c1f974e 775 {
576f8b11 776 AfxMessageBox (L"It is necessary to activate the edges selection mode\n"
777 L"and select edges on an object before \nrunning this function");
5c1f974e 778 return;
779 }
780
47162471 781 BRepFilletAPI_MakeFillet aFillet (aSelInteractive->Shape());
5c1f974e 782
783 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
7fd59977 784 {
47162471 785 const TopoDS_Shape& aSelShape = myAISContext->SelectedShape();
5c1f974e 786 if (aSelShape.ShapeType() != TopAbs_EDGE)
787 {
576f8b11 788 AfxMessageBox (L"It is necessary to activate the edges selection mode\n"
789 L"and select edges on an object before \nrunning this function");
7fd59977 790 return;
5c1f974e 791 }
7fd59977 792 }
7fd59977 793
47162471 794 BoxRadius aDialog (NULL,10.);
795 if (aDialog.DoModal() == IDOK)
5c1f974e 796 {
797 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
798 {
47162471 799 // Selected shape has its own location, and sub-shapes in the solid shape for fillet building
800 // don't have own locations. Fillet builder needs to know that input edge is just the same one as
801 // some sub-shape in our target solid shape, so no location is to be in input edge for fillet builder.
802 TopoDS_Shape aSelShape = myAISContext->SelectedShape().Located (TopLoc_Location());
803 aFillet.Add (aDialog.m_radius, TopoDS::Edge (aSelShape) );
5c1f974e 804 }
805 }
806 else
807 {
808 return;
809 }
810
811 TopoDS_Shape aNewShape;
812 try
813 {
814 aNewShape = aFillet.Shape();
815 }
816 catch (Standard_Failure)
817 {
576f8b11 818 AfxMessageBox (L"Error During Fillet computation");
5c1f974e 819 return;
820 }
821
47162471 822 aSelInteractive ->Set (aNewShape);
823 myAISContext->Redisplay (aSelInteractive);
5c1f974e 824 }
825
5c573e69 826 myCResultDialog.SetTitle("Make a fillet");
827 myCResultDialog.SetText(" Handle(AIS_Shape) S = Handle(AIS_Shape)::DownCast(myAISContext->Interactive()); \n"
5c1f974e 828 " \n"
829 " BRepAPI_MakeFillet aFillet(S->Shape()); \n"
830 " \n"
831 " TopoDS_Edge anEdge=TopoDS::Edge(myAISContext->SelectedShape()); \n"
832 " \n"
833 " aFillet.Add(dlg.m_radius,anEdge); \n"
834 " \n"
835 " TopoDS_Shape aNewShape = aFillet.Shape(); \n"
836 " \n"
837 " S->Set(aNewShape); \n"
838 " \n"
839 " myAISContext->Redisplay(S); \n"
840 " \n");
576f8b11 841 SetTitle (L"Make a fillet");
7fd59977 842}
5c1f974e 843
7fd59977 844// Create and display a circle with standard tools
845void CViewer3dDoc::OnCircle()
846{
5c1f974e 847 gp_Ax2 anAx2 (gp_Pnt (0., 0., 0.), gp_Dir(0., 0., -1.));
848 Handle(Geom_Circle) aGeomCircle = new Geom_Circle (anAx2, 300);
7fd59977 849
5c1f974e 850 // the lines above substitute
851 // GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.));
852 // Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value());
853
854 Handle(AIS_Circle) anAISCirc = new AIS_Circle(aGeomCircle);
855 myAISContext->Display (anAISCirc);
7fd59977 856
5c573e69 857 myCResultDialog.SetTitle("Create a circle");
858 myCResultDialog.SetText(" GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.)); \n"
5c1f974e 859 " \n"
860 " Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value()); \n"
861 " \n"
862 " myAISContext->Display(anAISCirc); \n"
863 " \n");
576f8b11 864 SetTitle (L"Create a circle");
7fd59977 865}
866
867void CViewer3dDoc::OnLine()
868{
5c1f974e 869 // TODO: Add your command handler code here
870 gp_Lin aGpLin (gp_Pnt (0., 0., 0.), gp_Dir(1., 0., 0.));
871 Handle(Geom_Line) aGeomLin = new Geom_Line (aGpLin);
872 Handle(AIS_Line) anAISLine = new AIS_Line (aGeomLin);
873 myAISContext->Display (anAISLine);
7fd59977 874
5c573e69 875 myCResultDialog.SetTitle("Create a line");
876 myCResultDialog.SetText(" gp_Lin L(gp_Pnt(0.,0.,0.),gp_Dir(1.,0.,0.)); \n"
5c1f974e 877 " \n"
878 " Handle(Geom_Line) aLine = new Geom_Line(L); \n"
879 " \n"
880 " Handle(AIS_Line) anAISLine = new AIS_Line(aLine); \n"
881 " \n"
882 " myAISContext->Display(anAISLine); \n"
883 " \n");
576f8b11 884 SetTitle (L"Create a line");
7fd59977 885}
886
887void CViewer3dDoc::OnNbisos()
888{
5c1f974e 889 int aNumU = myAISContext->DefaultDrawer()->UIsoAspect()->Number();
890 int aNumV = myAISContext->DefaultDrawer()->VIsoAspect()->Number();
7fd59977 891
5c1f974e 892 DlgIsos aDlg (NULL, aNumU, aNumV);
7fd59977 893
5c1f974e 894 if (aDlg.DoModal() == IDOK)
895 {
896 myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber (aDlg.m_isou);
897 myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber (aDlg.m_isov);
898
5c573e69 899 myCResultDialog.SetTitle("Iso Aspect");
900 myCResultDialog.SetText(" myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(dlg.m_isou); \n"
5c1f974e 901 " \n"
902 " myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(dlg.m_isov); \n"
903 " \n");
576f8b11 904 SetTitle (L"Iso Aspect");
5c1f974e 905 }
7fd59977 906}
907
908BOOL CViewer3dDoc::OnNewDocument()
909{
5c1f974e 910 if (!CDocument::OnNewDocument())
911 return FALSE;
7fd59977 912
5c1f974e 913 // TODO: add reinitialization code here
914 // (SDI documents will reuse this document)
7fd59977 915 SetTitle(myPresentation->GetName());
916
eb4320f2 917 myAISContext->EraseAll();
7fd59977 918 myAISContext->SetDisplayMode(AIS_Shaded);
919
920 POSITION pos = GetFirstViewPosition();
921 while (pos != NULL)
922 {
923 CViewer3dView* pView = (CViewer3dView*) GetNextView(pos);
924 pView->Reset();
925 }
926
5c1f974e 927 return TRUE;
7fd59977 928}
929
930void CViewer3dDoc::OnFileNew()
931{
932 OnNewDocument();
933}
934
935void CViewer3dDoc::InitViewButtons()
936{
937 POSITION pos = GetFirstViewPosition();
938 while (pos != NULL)
939 {
940 CViewer3dView* pView = (CViewer3dView*) GetNextView(pos);
941 pView->InitButtons();
942 }
943}
944
945void CViewer3dDoc::OnTextureOn()
946{
947 isTextureSampleStarted = TRUE;
948 Start();
949}
950
951void CViewer3dDoc::DoSample()
952{
953 InitViewButtons();
954
955 HCURSOR hOldCursor = ::GetCursor();
956 HCURSOR hNewCursor = AfxGetApp()->LoadStandardCursor(IDC_APPSTARTING);
957
958 SetCursor(hNewCursor);
959 {
960 try
961 {
962 myPresentation->DoSample();
963 }
964 catch (Standard_Failure)
965 {
966 Standard_SStream aSStream;
967 aSStream << "An exception was caught: " << Standard_Failure::Caught() << ends;
576f8b11 968 CString aMsg = aSStream.str().c_str();
7fd59977 969 AfxMessageBox (aMsg);
970 }
971 }
972 SetCursor(hOldCursor);
973}
974
975void CViewer3dDoc::OnBUTTONStart()
976{
eb4320f2 977 myAISContext->EraseAll();
7fd59977 978 myPresentation->FirstSample();
979 DoSample();
980}
981
982void CViewer3dDoc::OnBUTTONEnd()
983{
eb4320f2 984 myAISContext->EraseAll();
7fd59977 985 myPresentation->LastSample();
986 DoSample();
987}
988
989void CViewer3dDoc::OnBUTTONRepeat()
990{
991 DoSample();
992}
993
994void CViewer3dDoc::OnBUTTONNext()
995{
996 if (!myPresentation->AtLastSample())
997 {
998 myPresentation->NextSample();
999 DoSample();
1000 }
1001}
1002
1003void CViewer3dDoc::OnBUTTONPrev()
1004{
1005 if (!myPresentation->AtFirstSample())
1006 {
1007 myPresentation->PrevSample();
1008 DoSample();
1009 }
1010}
1011
1012void CViewer3dDoc::OnUpdateBUTTONNext(CCmdUI* pCmdUI)
1013{
1014 if ( isTextureSampleStarted )
1015 pCmdUI->Enable (!myPresentation->AtLastSample());
1016 else
1017 pCmdUI->Enable (FALSE);
1018}
1019
1020void CViewer3dDoc::OnUpdateBUTTONPrev(CCmdUI* pCmdUI)
1021{
1022 if ( isTextureSampleStarted )
1023 pCmdUI->Enable (!myPresentation->AtFirstSample());
1024 else
1025 pCmdUI->Enable (FALSE);
1026}
1027
1028void CViewer3dDoc::OnUpdateBUTTONStart(CCmdUI* pCmdUI)
1029{
1030 pCmdUI->Enable (isTextureSampleStarted);
1031}
1032
1033void CViewer3dDoc::OnUpdateBUTTONRepeat(CCmdUI* pCmdUI)
1034{
1035 pCmdUI->Enable (isTextureSampleStarted);
1036}
1037
1038void CViewer3dDoc::OnUpdateBUTTONEnd(CCmdUI* pCmdUI)
1039{
1040 pCmdUI->Enable (isTextureSampleStarted);
1041}
1042
12c76bee 1043void CViewer3dDoc::OnDumpView()
1044{
5c1f974e 1045 for (POSITION aPos = GetFirstViewPosition(); aPos != NULL;)
1046 {
1047 CViewer3dView* pView = (CViewer3dView* )GetNextView (aPos);
1048 pView->UpdateWindow();
7fd59977 1049 }
12c76bee 1050
5c1f974e 1051 myViewer->InitActiveViews();
1052 Handle(V3d_View) aView = myViewer->ActiveView();
12c76bee 1053 ExportView (aView);
7fd59977 1054}
1055
1056void CViewer3dDoc::Start()
1057{
1058 myPresentation->Init();
1059 OnBUTTONStart();
1060}
1061
1062void CViewer3dDoc::Fit()
1063{
1064 CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
1065 CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
1066 CViewer3dView *pView = (CViewer3dView *) pChild->GetActiveView();
1067 pView->FitAll();
1068}