1 // OcafDoc.cpp : implementation of the COcafDoc class
9 #include <ImportExport/ImportExport.h>
10 #include "AISDialogs.h"
12 // Dialog boxes classes
13 #include <ResultDialog.h>
14 #include <NewBoxDlg.h>
15 #include <NewCylDlg.h>
17 #include <TDF_Tool.hxx>
19 #include <DebugBrowser.hxx>
22 //#define new DEBUG_NEW // by cascade
24 static char THIS_FILE[] = __FILE__;
27 /////////////////////////////////////////////////////////////////////////////
30 IMPLEMENT_DYNCREATE(COcafDoc, CDocument)
32 BEGIN_MESSAGE_MAP(COcafDoc, OCC_3dBaseDoc)
33 //{{AFX_MSG_MAP(COcafDoc)
34 ON_COMMAND(ID_CREATEBOX, OnCreatebox)
35 ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
36 ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
37 ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
38 ON_COMMAND(ID_MODIFY, OnModify)
39 ON_UPDATE_COMMAND_UI(ID_MODIFY, OnUpdateModify)
40 ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo)
41 ON_COMMAND(ID_CUT, OnCut)
42 ON_COMMAND(ID_OBJECT_DELETE, OnObjectDelete)
43 ON_UPDATE_COMMAND_UI(ID_OBJECT_DELETE, OnUpdateObjectDelete)
44 ON_COMMAND(ID_FILE_SAVE, OnFileSave)
45 ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
46 ON_COMMAND(ID_CREATECYL, OnCreatecyl)
47 // ON_COMMAND(ID_DFBR, OnDfbr)
52 /////////////////////////////////////////////////////////////////////////////
53 // COcafDoc construction/destruction
63 BOOL COcafDoc::OnNewDocument()
65 if (!CDocument::OnNewDocument())
68 // Get an Handle on the current TOcaf_Application (which is initialized in the "Ocaf.h" file)
69 Handle(TOcaf_Application) OcafApp = ((COcafApp*)AfxGetApp())->GetApp();
71 // Create a new Ocaf document
72 OcafApp->NewDocument("MDTV-Standard",myOcafDoc);
73 TPrsStd_AISViewer::New(myOcafDoc->Main(),myViewer);
75 Handle(AIS_InteractiveContext) CTX;
76 TPrsStd_AISViewer::Find(myOcafDoc->Main(), CTX);
77 CTX->SetDisplayMode(AIS_Shaded);
80 // Set the maximum number of available "undo" actions
81 myOcafDoc->SetUndoLimit(10);
84 TCollection_AsciiString Message ("\
85 // Creation of a new document \n\
87 Handle(TOcaf_Application) OcafApp= ((COcafApp*)AfxGetApp())->GetApp(); \n\
89 // Creating the new document \n\
90 OcafApp->NewDocument(\"Ocaf-Sample\", myOcafDoc); \n\
92 // Creation of a new TPrsStd_AISViewer connected to the current V3d_Viewer\n\
93 TPrsStd_AISViewer::New(myOcafDoc->Main(),myViewer); \n\
95 // Setting the number of memorized undos \n\
96 myOcafDoc->SetUndoLimit(10); \n\
99 myCResultDialog.SetTitle(CString("New document"));
100 CString text(Message.ToCString());
101 myCResultDialog.SetText(text);
108 void COcafDoc::ActivateFrame(CRuntimeClass* pViewClass,int nCmdShow)
110 POSITION position = GetFirstViewPosition();
111 while (position != (POSITION)NULL)
113 CView* pCurrentView = (CView*)GetNextView(position);
114 if(pCurrentView->IsKindOf(pViewClass) )
116 ASSERT_VALID(pCurrentView);
117 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
118 ASSERT(pParentFrm != (CFrameWnd *)NULL);
119 // simply make the frame window visible
120 pParentFrm->ActivateFrame(nCmdShow);
126 /////////////////////////////////////////////////////////////////////////////
127 // COcafDoc diagnostics
130 void COcafDoc::AssertValid() const
132 CDocument::AssertValid();
135 void COcafDoc::Dump(CDumpContext& dc) const
141 /////////////////////////////////////////////////////////////////////////////
144 void COcafDoc::OnEditRedo()
147 myOcafDoc->CommitCommand();
148 myAISContext->UpdateCurrentViewer();
150 UpdateAllViews(NULL);
152 TCollection_AsciiString Message = TCollection_AsciiString("\
153 // Redo last undoes operation \n\
155 myOcafDoc->Redo(); \n\
157 myOcafDoc->CommitCommand(); \n\
161 myCResultDialog.SetTitle(CString("Redo"));
162 CString text(Message.ToCString());
163 myCResultDialog.SetText(text);
166 void COcafDoc::OnEditUndo()
169 myOcafDoc->CommitCommand();
170 myAISContext->UpdateCurrentViewer();
172 UpdateAllViews(NULL);
174 TCollection_AsciiString Message = TCollection_AsciiString("\
175 // Undo last operation \n\
177 myOcafDoc->Undo(); \n\
179 myOcafDoc->CommitCommand(); \n\
183 myCResultDialog.SetTitle(CString("Undo"));
184 CString text(Message.ToCString());
185 myCResultDialog.SetText(text);
188 void COcafDoc::OnUpdateEditRedo(CCmdUI* pCmdUI)
190 // Disable the "redo" button if there is no availlables redo actions
191 if (myOcafDoc->GetAvailableRedos()>0) pCmdUI->Enable(Standard_True);
192 else pCmdUI->Enable(Standard_False);
195 void COcafDoc::OnUpdateEditUndo(CCmdUI* pCmdUI)
197 // Disable the "undo" button if there is no availlables undo actions
198 if (myOcafDoc->GetAvailableUndos()>0) pCmdUI->Enable(Standard_True);
199 else pCmdUI->Enable(Standard_False);
202 void COcafDoc::OnCreatebox()
206 if(Dlg.DoModal()!=IDOK) return;
208 Handle(TDocStd_Document) D = GetOcafDoc();
210 // Open a new command (for undo)
212 TOcaf_Commands TSC(D->Main());
214 TCollection_AsciiString Name((Standard_CString)(LPCTSTR)Dlg.m_Name);
216 // Create a new box using the CNewBoxDlg Dialog parameters as attributes
217 TDF_Label L=TSC.CreateBox(Dlg.m_x, Dlg.m_y, Dlg.m_z, Dlg.m_w, Dlg.m_l, Dlg.m_h, TCollection_ExtendedString(Name));
219 // Get the TPrsStd_AISPresentation of the new box TNaming_NamedShape
220 Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID());
224 // Attach an integer attribute to L to memorize it's displayed
225 TDataStd_Integer::Set(L, 1);
226 myAISContext->UpdateCurrentViewer();
228 // Close the command (for undo)
232 TCollection_AsciiString Message ("\
233 // Creation of a new box using Ocaf attributes \n\
235 Handle(TDocStd_Document) D = GetOcafDoc(); \n\
237 // Openning a new command (for undo/redo) \n\
240 TOcaf_Commands TSC(D->Main()); \n\
241 // Look at the TOcaf_Commands::CreateBox() function \n\
242 TDF_Label L=TSC.CreateBox(m_x, m_y, m_z, m_w, m_l, m_h, Name); \n\
244 // Set the TPrsStd_AISPresentation of the box \n\
245 Handle(TPrsStd_AISPresentation) prs; \n\
246 prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID()); \n\
248 // Displaying the box \n\
251 // Commint the command (for undo/redo) \n\
252 D->CommitCommand(); \n\
255 myCResultDialog.SetTitle(CString("Create box"));
256 CString text(Message.ToCString());
257 myCResultDialog.SetText(text);
260 void COcafDoc::OnCreatecyl()
264 if(Dlg.DoModal()!=IDOK) return;
266 Handle(TDocStd_Document) D = GetOcafDoc();
268 // Open a new command (for undo)
270 TOcaf_Commands TSC(D->Main());
272 TCollection_AsciiString Name((Standard_CString)(LPCTSTR)Dlg.m_Name);
274 // Create a new box using the CNewCylDlg Dialog parameters as attributes
275 TDF_Label L=TSC.CreateCyl(Dlg.m_x, Dlg.m_y, Dlg.m_z, Dlg.m_r, Dlg.m_h, TCollection_ExtendedString(Name));
277 // Get the TPrsStd_AISPresentation of the new cylinder TNaming_NamedShape
278 Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID());
282 // Attach an integer attribute to L to memorize it's displayed
283 TDataStd_Integer::Set(L, 1);
284 myAISContext->UpdateCurrentViewer();
286 // Close the command (for undo)
290 TCollection_AsciiString Message ("\
291 // Creation of a new cylinder using Ocaf attributes \n\
293 Handle(TDocStd_Document) D = GetOcafDoc(); \n\
295 // Openning a new command (for undo/redo) \n\
298 TOcaf_Commands TSC(D->Main()); \n\
299 // Look at the TOcaf_Commands::CreateCyl() function \n\
300 TDF_Label L=TSC.CreateCyl(m_x, m_y, m_z, m_r, m_h, Name); \n\
302 // Set the TPrsStd_AISPresentation of the cylinder \n\
303 Handle(TPrsStd_AISPresentation) prs; \n\
304 prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID()); \n\
306 // Displaying the cylinder \n\
309 // Commint the command (for undo/redo) \n\
310 D->CommitCommand(); \n\
313 myCResultDialog.SetTitle(CString("Create cylinder"));
314 CString text(Message.ToCString());
315 myCResultDialog.SetText(text);
318 void COcafDoc::OnModify()
320 // Get the selected interactive object
321 myAISContext->InitCurrent();
322 Handle(AIS_InteractiveObject) curAISObject = myAISContext->Current();
325 // Get the main label of the selected object
326 Handle(TPrsStd_AISPresentation) ObjectPrs =
327 Handle(TPrsStd_AISPresentation)::DownCast(curAISObject->GetOwner());
328 TDF_Label LabObject = ObjectPrs->Label();
330 // Get the TFunction_Function attribute of the selected object
331 Handle(TFunction_Function) TFF;
332 if ( !LabObject.FindAttribute(TFunction_Function::GetID(),TFF) )
334 MessageBox(0,"Object cannot be modify.", "Modification", MB_ICONEXCLAMATION);
337 // Get the Standard_GUID of the TFunction_FunctionDriver of the selected object TFunction_Function attribute
338 Standard_GUID myDriverID=TFF->GetDriverGUID();
340 Handle(TDocStd_Document) D = GetOcafDoc();
341 TFunction_Logbook log;
343 TCollection_AsciiString Message("\
344 // Modification and recomputation of the selected object \n\
346 Handle(TDocStd_Document) D = GetOcafDoc(); \n\
348 // Getting the TPrsStd_AISPresentation of the selected object \n\
349 Handle(TPrsStd_AISPresentation) ObjectPrs = \n\
350 Handle(TPrsStd_AISPresentation)::DownCast(curAISObject->GetOwner()); \n\
352 // Getting the Label of the selected object using the TPrsStd_AISPresentation \n\
353 TDF_Label LabObject = ObjectPrs->Label(); \n\
355 // Getting the TFunction_FunctionDriver ID attached to this label \n\
356 Handle(TFunction_Function) TFF; \n\
358 TCollection_AsciiString Suite;
360 // Case of a box created with the box function driver
361 if(myDriverID==TOcafFunction_BoxDriver::GetID())
364 Standard_Real x, y, z, w, l, h;
366 // Get the attributes values of the current box
367 Handle(TDataStd_Real) curReal;
368 LabObject.FindChild(1).FindAttribute(TDataStd_Real::GetID(),curReal);
370 LabObject.FindChild(2).FindAttribute(TDataStd_Real::GetID(),curReal);
372 LabObject.FindChild(3).FindAttribute(TDataStd_Real::GetID(),curReal);
374 LabObject.FindChild(4).FindAttribute(TDataStd_Real::GetID(),curReal);
376 LabObject.FindChild(5).FindAttribute(TDataStd_Real::GetID(),curReal);
378 LabObject.FindChild(6).FindAttribute(TDataStd_Real::GetID(),curReal);
380 Handle(TDataStd_Name) stdName;
381 LabObject.FindAttribute(TDataStd_Name::GetID(),stdName);
383 // Initialize the dialog box with the values of the current box
384 Dlg.InitFields(x, y, z, w, l, h, stdName->Get());
386 if(Dlg.DoModal()!=IDOK) return;
388 // Open a new command (for undo)
391 TCollection_AsciiString Name((Standard_CString)(LPCTSTR)Dlg.m_Name);
394 TOcaf_Commands TSC(LabObject);
395 TSC.ModifyBox(Dlg.m_x, Dlg.m_y, Dlg.m_z, Dlg.m_w, Dlg.m_l, Dlg.m_h, TCollection_ExtendedString(Name), log);
397 // Get the presentation of the box, display it and set it selected
398 Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID());
399 TDataStd_Integer::Set(LabObject, 1);
401 myAISContext->UpdateCurrentViewer();
402 // Close the command (for undo)
407 // In this case the TFunction_FunctionDriver ID is a BoxDriver \n\
408 if(myDriverID==TOcafFunction_BoxDriver::GetID()){ \n\
410 // Getting values of box attributes \n\
411 Handle(TDataStd_Real) curReal; \n\
412 LabObject.FindChild(1).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
413 w=curReal->Get(); \n\
414 LabObject.FindChild(2).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
415 l=curReal->Get(); \n\
416 LabObject.FindChild(3).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
417 h=curReal->Get(); \n\
418 LabObject.FindChild(4).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
419 x=curReal->Get(); \n\
420 LabObject.FindChild(5).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
421 y=curReal->Get(); \n\
422 LabObject.FindChild(6).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
423 z=curReal->Get(); \n\
424 Handle(TDataStd_Name) stdName; \n\
425 LabObject.FindAttribute(TDataStd_Name::GetID(),stdName); \n\
427 // Openning a new command \n\
430 TOcaf_Commands TSC(LabObject); \n\
431 // Look at the TOcaf_Commands::ModifyBox() function \n\
432 TSC.ModifyBox(m_x, m_y, m_z, m_w, m_l, m_h, Name); \n\
434 // Set the TPrsStd_AISPresentation of the box \n\
435 Handle(TPrsStd_AISPresentation) prs; \n\
436 prs= TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID()); \n\
438 // Display the box \n\
441 // Commit the command \n\
442 D->CommitCommand(); \n\
445 myCResultDialog.SetTitle(CString("Modify Box"));
447 // Case of a cylinder created with the box function driver
448 else if(myDriverID==TOcafFunction_CylDriver::GetID())
451 Standard_Real x, y, z, r, h;
453 // Get the attributes values of the current box
454 Handle(TDataStd_Real) curReal;
455 LabObject.FindChild(1).FindAttribute(TDataStd_Real::GetID(),curReal);
457 LabObject.FindChild(2).FindAttribute(TDataStd_Real::GetID(),curReal);
459 LabObject.FindChild(3).FindAttribute(TDataStd_Real::GetID(),curReal);
461 LabObject.FindChild(4).FindAttribute(TDataStd_Real::GetID(),curReal);
463 LabObject.FindChild(5).FindAttribute(TDataStd_Real::GetID(),curReal);
465 Handle(TDataStd_Name) stdName;
466 LabObject.FindAttribute(TDataStd_Name::GetID(),stdName);
468 // Initialize the dialog cylinder with the values of the current cylinder
469 Dlg.InitFields(x, y, z, r, h, stdName->Get());
471 if(Dlg.DoModal()!=IDOK) return;
473 // Open a new command (for undo)
476 TCollection_AsciiString Name((Standard_CString)(LPCTSTR)Dlg.m_Name);
478 // Modify the cylinder
479 TOcaf_Commands TSC(LabObject);
480 TSC.ModifyCyl(Dlg.m_x, Dlg.m_y, Dlg.m_z, Dlg.m_r, Dlg.m_h, TCollection_ExtendedString(Name), log);
482 // Get the presentation of the cylinder, display it and set it selected
483 Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID());
484 TDataStd_Integer::Set(LabObject, 1);
486 myAISContext->UpdateCurrentViewer();
487 // Close the command (for undo)
492 // In this case the TFunction_FunctionDriver ID is a CylDriver \n\
493 if(myDriverID==TOcafFunction_CylDriver::GetID()){ \n\
495 // Getting values of box cylinder \n\
496 Handle(TDataStd_Real) curReal; \n\
497 LabObject.FindChild(1).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
498 r=curReal->Get(); \n\
499 LabObject.FindChild(2).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
500 h=curReal->Get(); \n\
501 LabObject.FindChild(3).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
502 x=curReal->Get(); \n\
503 LabObject.FindChild(4).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
504 y=curReal->Get(); \n\
505 LabObject.FindChild(5).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
506 z=curReal->Get(); \n\
507 Handle(TDataStd_Name) stdName; \n\
508 LabObject.FindAttribute(TDataStd_Name::GetID(),stdName); \n\
510 // Openning a new command \n\
513 TOcaf_Commands TSC(LabObject); \n\
514 // Look at the TOcaf_Commands::ModifyCyl() function \n\
515 TSC.ModifyCyl(m_x, m_y, m_z, m_r, m_h, Name); \n\
517 // Set the TPrsStd_AISPresentation of the cylinder \n\
518 Handle(TPrsStd_AISPresentation) prs; \n\
519 prs= TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID()); \n\
521 // Display the cylinder \n\
524 // Commit the command \n\
525 D->CommitCommand(); \n\
528 myCResultDialog.SetTitle(CString("Modify cylinder"));
530 // Case of a cut solid created with the cut function driver
531 else if(myDriverID==TOcafFunction_CutDriver::GetID())
533 // Open a new command (for undo)
536 // Get the reference of the Original object used to make the cut object,
537 // this reference is here attached to the first child of the cut object label
538 Handle(TDF_Reference) OriginalRef;
539 LabObject.FindChild(1).FindAttribute(TDF_Reference::GetID(),OriginalRef);
541 // Get the presentation of the Original object
542 Handle(TPrsStd_AISPresentation) OriginalPrs= TPrsStd_AISPresentation::Set(OriginalRef->Get(), TNaming_NamedShape::GetID());
544 // Get the reference of the Tool object used to make the cut object,
545 // this reference is here attached to the second child of the cut object label
546 Handle(TDF_Reference) ToolRef;
547 LabObject.FindChild(2).FindAttribute(TDF_Reference::GetID(),ToolRef);
548 TDF_Label ToolLab=ToolRef->Get();
551 // Get the presentation of the Tool object
552 Handle(TPrsStd_AISPresentation) ToolPrs= TPrsStd_AISPresentation::Set(ToolLab, TNaming_NamedShape::GetID());
554 // Display the Original object and the Tool object, erase the cut object.
555 TDataStd_Integer::Set(OriginalRef->Get(), 1);
556 OriginalPrs->Display(1);
557 TDataStd_Integer::Set(ToolLab, 1);
559 TDataStd_Integer::Set(LabObject, 0);
561 myAISContext->UpdateCurrentViewer();
563 // In this we decided to modify the tool object which is a cylinder,
564 // so we open the cylinder parameters dialog box
566 Standard_Real x, y, z, h, r;
568 // Get the attributes values of the tool cylinder
569 Handle(TDataStd_Real) curReal;
570 ToolLab.FindChild(1).FindAttribute(TDataStd_Real::GetID(),curReal);
572 ToolLab.FindChild(2).FindAttribute(TDataStd_Real::GetID(),curReal);
574 ToolLab.FindChild(3).FindAttribute(TDataStd_Real::GetID(),curReal);
576 ToolLab.FindChild(4).FindAttribute(TDataStd_Real::GetID(),curReal);
578 ToolLab.FindChild(5).FindAttribute(TDataStd_Real::GetID(),curReal);
580 Handle(TDataStd_Name) stdName;
581 ToolLab.FindAttribute(TDataStd_Name::GetID(),stdName);
583 // Initialize the dialog box with the values of the tool cylinder
584 Dlg.InitFields(x, y, z, r, h, stdName->Get());
586 if(Dlg.DoModal()!=IDOK)
589 myAISContext->UpdateCurrentViewer();
592 TCollection_AsciiString Name((Standard_CString)(LPCTSTR)Dlg.m_Name);
594 // Modify the cylinder
595 TOcaf_Commands ToolTSC(ToolLab);
596 ToolTSC.ModifyCyl(Dlg.m_x, Dlg.m_y, Dlg.m_z, Dlg.m_r, Dlg.m_h, TCollection_ExtendedString(Name), log);
598 // Redisplay the modified Tool object
599 TDataStd_Integer::Set(ToolLab, 1);
601 myAISContext->UpdateCurrentViewer();
604 // Get the TOcafFunction_CutDriver using its Standard_GUID in the TFunction_DriverTable
605 Handle(TOcafFunction_CutDriver) myCutDriver;
606 TFunction_DriverTable::Get()->FindDriver(myDriverID, myCutDriver);
608 // Recompute the cut object if it must be (look at the MustExecute function code)
609 // if (myCutDriver->MustExecute(log))
611 log.SetTouched(LabObject);
612 if(myCutDriver->Execute(log))
613 MessageBox(0,"Recompute failed","Modify cut",MB_ICONEXCLAMATION);
616 // Erase the Original object and the Tool objectedisplay the modified Tool object
617 TDataStd_Integer::Set(ToolLab, 0);
619 TDataStd_Integer::Set(OriginalRef->Get(), 0);
620 OriginalPrs->Erase(0);
621 ObjectPrs=TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID());
622 TDataStd_Integer::Set(LabObject, 1);
623 ObjectPrs->Display(1);
624 myAISContext->UpdateCurrentViewer();
625 // Close the command (for undo)
630 // In this case the TFunction_FunctionDriver ID is a CutDriver \n\
631 if(myDriverID==TOcafFunction_CutDriver::GetID()){ \n\
633 // Getting values of cut attributes (which are reference to the shapes)\n\
634 Handle(TDF_Reference) OriginalRef; \n\
635 LabObject.FindChild(1).FindAttribute(TDF_Reference::GetID(),OriginalRef); \n\
636 Handle(TDF_Reference) ToolRef; \n\
637 LabObject.FindChild(2).FindAttribute(TDF_Reference::GetID(),ToolRef); \n\
639 // Getting the label of the tool shape (to modify it)\n\
640 TDF_Label ToolLab=ToolRef->Get(); \n\
642 TOcaf_Commands TSC(ToolLab); \n\
643 // Look at the TOcaf_Commands::ModifyBox() function \n\
644 TSC.ModifyBox(m_x, m_y, m_z, m_w, m_l, m_h, Name); \n\
646 // Getting the TOcafFunction_CutDriver used to create the cut\n\
647 Handle(TOcafFunction_CutDriver) myCutDriver; \n\
648 TFunction_DriverTable::Get()->FindDriver(myDriverID, myCutDriver); \n\
650 // Recompute the cut if it must be (if an attribute was modified)\n\
651 if (myCutDriver->MustExecute(log)) { \n\
652 log.SetTouched(LabObject); \n\
653 myCutDriver->Execute(log) \n\
655 Handle(TPrsStd_AISPresentation) prs; \n\
657 // Setting the TPrsStd_AISPresentation of the cut object\n\
658 prs= TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID()); \n\
660 // Display the TPrsStd_AISPresentation of the cut object\n\
663 // Commit the command\n\
664 D->CommitCommand(); \n\
667 myCResultDialog.SetTitle(CString("Modify Cut"));
671 MessageBox(0,"No associated function driver","Modify",MB_OK);
674 CString text(Message.ToCString());
675 myCResultDialog.SetText(text);
678 void COcafDoc::OnUpdateModify(CCmdUI* pCmdUI)
680 // Disable the "modify" button if there is no selected object or several selected objects
681 myAISContext->InitCurrent();
682 if(myAISContext->NbCurrents()!=1)
684 pCmdUI->Enable(Standard_False);
688 // Get the root label of the selected object using its TPrsStd_AISPresentation
689 myAISContext->InitCurrent();
690 Handle(TPrsStd_AISPresentation) ObjectPrs =
691 Handle(TPrsStd_AISPresentation)::DownCast(myAISContext->Current()->GetOwner());
692 if (!ObjectPrs.IsNull()){
693 TDF_Label LabObject = ObjectPrs->Label();
696 // Disable the "modify" button if selected object don't have a TFunction_Function attribute
697 Handle(TFunction_Function) TFF;
698 pCmdUI->Enable(LabObject.FindAttribute(TFunction_Function::GetID(),TFF) );
701 pCmdUI->Enable(FALSE);
705 void COcafDoc::OnCut()
708 Handle(TDocStd_Document) D = GetOcafDoc();
709 TDF_Label L = D->Main();
711 TOcaf_Commands TSC(L);
713 // Open a new command (for undo)
716 // Create a new cyl (10*20 dimensions)
717 TDF_Label L2=TSC.CreateCyl(0, 10, -10, 5, 80, "Cylinder");
718 Handle(TPrsStd_AISPresentation) prs1= TPrsStd_AISPresentation::Set(L2, TNaming_NamedShape::GetID());
719 prs1->SetColor(Quantity_NOC_MATRABLUE);
720 TDataStd_Integer::Set(L2, 1);
724 // Wait a second to see the construction
727 // Create a new box (20*20*20 dimensions, at the (-12,0,10) position)
728 TDF_Label L1=TSC.CreateBox(-12, 0, 10, 20, 30, 40, "Box");
729 Handle(TPrsStd_AISPresentation) prs2= TPrsStd_AISPresentation::Set(L1, TNaming_NamedShape::GetID());
730 prs2->SetColor(Quantity_NOC_YELLOW);
731 TDataStd_Integer::Set(L1, 1);
739 Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID());
741 // Erase the two boxes and display the cut object
742 TDataStd_Integer::Set(L1, 0);
744 TDataStd_Integer::Set(L2, 0);
746 TDataStd_Integer::Set(L, 1);
748 myAISContext->UpdateCurrentViewer();
750 // Close the cut operation command (for undo)
754 TCollection_AsciiString Message ("\
755 // Cut operation between a cylinder and a box \n\
757 Handle(TDocStd_Document) D = GetOcafDoc(); \n\
758 TDF_Label L = D->Main(); \n\
760 // Openning a new command\n\
763 TOcaf_Commands TSC(D->Main()); \n\
766 // Look at the TOcaf_Commands::CreateBox() function \n\
767 TDF_Label L1=TSC.CreateBox(-12, 0, 10, 24, 20, 20, '\"'Box'\"'); \n\
768 // Look at the TOcaf_Commands::Cut() function \n\
770 // Create a cylinder \n\
771 // Look at the TOcaf_Commands::CreateCyl() function \n\
772 // Create two boxes \n\
773 TDF_Label L2=TSC.CreateCyl(0, 0, 0, 10, 20, '\"'Cylinder'\"'); \n\
775 // Cut the cylinder with the box \n\
776 L=TSC.Cut(L1, L2); \n\
777 Handle(TPrsStd_AISPresentation) prs; \n\
779 // Setting the TPrsStd_AISPresentation of the cut object\n\
780 prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID()); \n\
782 // Displaying the TPrsStd_AISPresentation of the cut object\n\
785 // Commit the command\n\
786 D->CommitCommand(); \n\
789 myCResultDialog.SetTitle(CString("Cut operation"));
790 CString text(Message.ToCString());
791 myCResultDialog.SetText(text);
795 void COcafDoc::Fit3DViews()
797 POSITION position = GetFirstViewPosition();
798 while (position != (POSITION)NULL)
800 CView* pCurrentView = (CView*)GetNextView(position);
801 if(pCurrentView->IsKindOf( RUNTIME_CLASS( OCC_3dView ) ) )
803 ASSERT_VALID(pCurrentView);
804 OCC_3dView* aOCC_3dView = (OCC_3dView*)pCurrentView;
805 aOCC_3dView->FitAll();
811 void COcafDoc::OnObjectDelete()
813 Handle(TDocStd_Document) D = GetOcafDoc();
817 AIS_SequenceOfInteractive aSequence;
818 for(myAISContext->InitCurrent();
819 myAISContext->MoreCurrent();
820 myAISContext->NextCurrent())
821 aSequence.Append(myAISContext->Current());
823 for(int iter=1;iter <=aSequence.Length();iter++)
825 if (myAISContext->DisplayStatus(aSequence(iter)) == AIS_DS_Displayed)
827 Handle(TPrsStd_AISPresentation) CurrentPrs
828 = Handle(TPrsStd_AISPresentation)::DownCast(aSequence(iter)->GetOwner());
829 TDataStd_Integer::Set(CurrentPrs->Label(), 0);
830 CurrentPrs->Erase(1);
835 myAISContext->UpdateCurrentViewer();
837 TCollection_AsciiString Message ("\
838 // Delete selected object \n\
840 Handle(TDocStd_Document) D = GetOcafDoc(); \n\
842 // Openning a new command\n\
845 // Getting the TPrsStd_AISPresentation of the selected object\n\
846 Handle(TPrsStd_AISPresentation) CurrentPrs \n\
847 =Handle(TPrsStd_AISPresentation)::DownCast(myAISContext->Current()->GetOwner()); \n\
849 // Erasing the TPrsStd_AISPresentation of the selected object\n\
850 CurrentPrs->Erase(1); \n\
852 // Commit the command\n\
853 D->CommitCommand(); \n\
856 myCResultDialog.SetTitle(CString("Delete"));
857 CString text(Message.ToCString());
858 myCResultDialog.SetText(text);
861 void COcafDoc::OnUpdateObjectDelete(CCmdUI* pCmdUI)
863 myAISContext->InitCurrent();
864 pCmdUI->Enable (myAISContext->MoreCurrent());
867 void COcafDoc::DisplayPrs()
869 TDF_Label LabSat = myOcafDoc->Main();
871 for (TDF_ChildIterator it(LabSat); it.More(); it.Next())
873 TDF_Label L = it.Value();
874 Handle(TNaming_NamedShape) TNS;
875 if (!L.FindAttribute(TNaming_NamedShape::GetID(), TNS)) continue;
876 Handle(TDataStd_Integer) TDI;
878 // To know if the object was displayed
879 if (L.FindAttribute(TDataStd_Integer::GetID(), TDI))
880 if(!TDI->Get()) continue;
882 Handle(TPrsStd_AISPresentation) prs;
883 if (!L.FindAttribute(TPrsStd_AISPresentation::GetID(),prs))
884 prs = TPrsStd_AISPresentation::Set(L,TNaming_NamedShape::GetID());
885 prs->SetColor(Quantity_NOC_ORANGE);
889 myAISContext->UpdateCurrentViewer();
892 void COcafDoc::OnCloseDocument()
894 Handle(TOcaf_Application) OcafApp = ((COcafApp*)AfxGetApp())->GetApp();
895 OcafApp->Close(myOcafDoc);
896 CDocument::OnCloseDocument();
899 void COcafDoc::OnFileSaveAs()
901 Standard_CString SPathName = (Standard_CString) (LPCTSTR) PathName;
902 TCollection_ExtendedString TPathName(SPathName);
906 if (TPathName.SearchFromEnd(".xml") > 0){
907 Filter = "OCAFSample(XML) (*.xml)|*.xml|OCAFSample(STA) (*.sta)|*.sta|OCAFSample(Binary) (*.cbf)|*.cbf||";
909 else if (TPathName.SearchFromEnd(".cbf") > 0){
910 Filter = "OCAFSample(Binary) (*.cbf)|*.cbf|OCAFSample(STA) (*.sta)|*.sta|OCAFSample(XML) (*.xml)|*.xml||";
913 Filter = "OCAFSample(STA) (*.sta)|*.sta|OCAFSample(XML) (*.xml)|*.xml|OCAFSample(Binary) (*.cbf)|*.cbf||";
916 CFileDialog dlg(FALSE,
919 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
921 // "sta Files (*.sta)|*.sta; |All Files (*.*)|*.*||",
925 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp();
926 if (dlg.DoModal() != IDOK) return;
928 SetTitle(dlg.GetFileTitle());
930 CWaitCursor aWaitCursor;
931 CString CSPath = dlg.GetPathName();
933 // if((CSPath.Find(CString(".sta")))==-1 )
934 // CSPath = CSPath + ".sta";
936 cout << "Save As " << CSPath << endl;
938 Standard_CString SPath = (Standard_CString) (LPCTSTR) CSPath;
939 TCollection_ExtendedString TPath(SPath);
941 if (TPath.SearchFromEnd(".xml") > 0)
943 // The document must be saved in XML format
944 myOcafDoc->ChangeStorageFormat("XmlOcaf");
946 else if (TPath.SearchFromEnd(".cbf") > 0)
948 // The document must be saved in binary format
949 myOcafDoc->ChangeStorageFormat("BinOcaf");
953 // The document must be saved in standard format
954 myOcafDoc->ChangeStorageFormat("MDTV-Standard");
959 // Saves the document in the current application
960 m_App->SaveAs(myOcafDoc,TPath);
964 AfxMessageBox("Error! The file wasn't saved.");
967 // // save the document in the current application
968 // m_App->SaveAs(myOcafDoc,TPath);
972 TCollection_AsciiString Message = TCollection_AsciiString("\
973 // Storing the document as \n\
975 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp(); \n\
977 // Saving current OCAF document at TPath \n\
978 m_App->SaveAs(myOcafDoc,(TCollection_ExtendedString) TPath); \n\
981 myCResultDialog.SetTitle(CString("Save a document"));
982 CString text(Message.ToCString());
983 myCResultDialog.SetText(text);
986 void COcafDoc::OnFileSave()
988 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp();
991 if (myOcafDoc.IsNull())
993 AfxMessageBox("Error during saving! Empty document.");
999 Standard_CString SPath = (Standard_CString) (LPCTSTR) PathName;
1000 TCollection_ExtendedString TPath(SPath);
1002 if (TPath.SearchFromEnd(".xml") > 0)
1004 // The document must be saved in XML format
1005 myOcafDoc->ChangeStorageFormat("XmlOcaf");
1007 else if (TPath.SearchFromEnd(".cbf") > 0)
1009 // The document must be saved in binary format
1010 myOcafDoc->ChangeStorageFormat("BinOcaf");
1014 // The document must be saved in standard format
1015 myOcafDoc->ChangeStorageFormat("MDTV-Standard");
1020 // Saves the document in the current application
1021 m_App->SaveAs(myOcafDoc,TPath);
1025 AfxMessageBox("Error! The file wasn't saved.");
1029 TCollection_AsciiString Message = TCollection_AsciiString("\
1030 // Storing the document \n\
1032 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp(); \n\
1034 // Saving current OCAF document at TPath \n\
1035 m_App->SaveAs(myOcafDoc,(TCollection_ExtendedString) TPath); \n\
1038 myCResultDialog.SetTitle(CString("Save a document"));
1039 CString text(Message.ToCString());
1040 myCResultDialog.SetText(text);
1044 CFileDialog dlg(FALSE,
1047 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
1048 "OCAFSample(STA) (*.sta)|*.sta|OCAFSample(XML) (*.xml)|*.xml|OCAFSample(Binary) (*.cbf)|*.cbf||",
1049 // "sta Files (*.sta)|*.sta; |All Files (*.*)|*.*||",
1052 if (dlg.DoModal() != IDOK) return;
1054 SetTitle(dlg.GetFileTitle());
1056 CWaitCursor aWaitCursor;
1057 CString CSPath = dlg.GetPathName();
1059 Standard_CString SPath = (Standard_CString)(LPCTSTR) CSPath;
1060 TCollection_ExtendedString TPath(SPath);
1062 // Choose storage format
1063 if (TPath.SearchFromEnd(".xml") > 0)
1065 // The document must be saved in XML format
1066 myOcafDoc->ChangeStorageFormat("XmlOcaf");
1068 else if (TPath.SearchFromEnd(".cbf") > 0)
1070 // The document must be saved in binary format
1071 myOcafDoc->ChangeStorageFormat("BinOcaf");
1075 // The document must be saved in standard format
1076 myOcafDoc->ChangeStorageFormat("Ocaf-Sample");
1081 // Saves the document in the current application
1082 m_App->SaveAs(myOcafDoc,TPath);
1086 AfxMessageBox("Error! The file wasn't saved.");
1091 // if((CSPath.Find(CString(".sta")))==-1 )
1092 // CSPath = CSPath + ".sta";
1094 // cout << "Save As " << CSPath << endl;
1096 // Standard_CString SPath = (Standard_CString) (LPCTSTR) CSPath;
1097 // TCollection_ExtendedString TPath(SPath);
1099 // save the document in the current application
1100 // m_App->SaveAs(myOcafDoc,TPath);
1106 TCollection_AsciiString Message = TCollection_AsciiString("\
1107 // Storing the document as \n\
1109 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp(); \n\
1111 // Saving current OCAF document at TPath \n\
1112 m_App->SaveAs(myOcafDoc,(TCollection_ExtendedString) TPath); \n\
1115 myCResultDialog.SetTitle(CString("Save a document"));
1116 CString text(Message.ToCString());
1117 myCResultDialog.SetText(text);
1120 BOOL COcafDoc::OnOpenDocument(LPCTSTR lpszPathName)
1122 if (!CDocument::OnOpenDocument(lpszPathName))
1125 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp();
1127 CWaitCursor aWaitCursor;
1128 PathName=lpszPathName;
1130 Standard_CString SPath = (Standard_CString) lpszPathName;
1131 TCollection_ExtendedString TPath(SPath);
1132 PathName=lpszPathName;
1134 // open the document in the current application
1136 CDF_RetrievableStatus RS = m_App->Open(TPath,myOcafDoc);
1138 //connect the document CAF (myDoc) with the AISContext (myAISContext)
1139 // TPrsStd_AISViewer::Has(myOcafDoc->Main());
1140 TPrsStd_AISViewer::New(myOcafDoc->Main(),myViewer);
1141 myOcafDoc->SetUndoLimit(10);
1143 Handle(AIS_InteractiveContext) CTX;
1144 TPrsStd_AISViewer::Find(myOcafDoc->Main(),CTX);
1145 CTX->SetDisplayMode(AIS_Shaded);
1149 // Display the presentations (which was not stored in the document)
1152 TCollection_AsciiString Message = TCollection_AsciiString("\
1153 // Retrieve a document \n\
1155 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp(); \n\
1157 // Openning the OCAF document from the TPath file\n\
1158 m_App->Open((TCollection_ExtendedString) TPath,myOcafDoc); \n\
1160 // Creation of a new TPrsStd_AISViewer connected to the current V3d_Viewer\n\
1161 TPrsStd_AISViewer::New(myOcafDoc->Main(),myViewer); \n\
1163 // Setting the number of memorized undos \n\
1164 myOcafDoc->SetUndoLimit(10); \n\
1167 myCResultDialog.SetTitle(CString("Open a document"));
1168 CString text(Message.ToCString());
1169 myCResultDialog.SetText(text);
1176 void COcafDoc::EraseAll()
1178 myOcafDoc->NewCommand();
1180 TDF_Label LabSat = myOcafDoc->Main();
1182 for (TDF_ChildIterator it(LabSat); it.More(); it.Next())
1184 TDF_Label L = it.Value();
1185 Handle(TNaming_NamedShape) TNS;
1186 if (!L.FindAttribute(TNaming_NamedShape::GetID(), TNS)) continue;
1187 Handle(TDataStd_Integer) TDI;
1189 // To know if the object was displayed
1190 if (L.FindAttribute(TDataStd_Integer::GetID(), TDI))
1191 if(!TDI->Get()) continue;
1193 Handle(TPrsStd_AISPresentation) prs;
1194 if (!L.FindAttribute(TPrsStd_AISPresentation::GetID(),prs))
1195 prs = TPrsStd_AISPresentation::Set(L,TNaming_NamedShape::GetID());
1196 prs->SetColor(Quantity_NOC_ORANGE);
1200 myAISContext->UpdateCurrentViewer();
1202 myOcafDoc->CommitCommand();
1205 void COcafDoc::Popup(const Standard_Integer x,
1206 const Standard_Integer y ,
1207 const Handle(V3d_View)& aView )
1209 Standard_Integer PopupMenuNumber=0;
1210 myAISContext->InitCurrent();
1211 if (myAISContext->MoreCurrent())
1215 VERIFY(menu.LoadMenu(IDR_Popup3D));
1216 CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber);
1218 ASSERT(pPopup != NULL);
1219 if (PopupMenuNumber == 1) // more than 1 object.
1221 bool OneOrMoreInShading = false;
1222 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
1223 if (myAISContext->IsDisplayed(myAISContext->Current(),1)) OneOrMoreInShading=true;
1224 if(!OneOrMoreInShading)
1225 pPopup->EnableMenuItem(5, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
1228 POINT winCoord = { x , y };
1229 Handle(WNT_Window) aWNTWindow=
1230 Handle(WNT_Window)::DownCast(aView->Window());
1231 ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord);
1232 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y ,
1239 //void COcafDoc::OnDfbr()
1241 // // TODO: Add your command handler code here
1242 // DebugBrowser::DFBrowser(myOcafDoc);