0025284: Problems with standard MFC samples
[occt.git] / samples / mfc / standard / 06_Ocaf / src / OcafDoc.cpp
CommitLineData
7fd59977 1// OcafDoc.cpp : implementation of the COcafDoc class
2//
3
4#include "StdAfx.h"
5
6#include "OcafDoc.h"
7
8#include "OcafApp.h"
9#include <ImportExport/ImportExport.h>
10#include "AISDialogs.h"
11
12// Dialog boxes classes
13#include <ResultDialog.h>
14#include <NewBoxDlg.h>
15#include <NewCylDlg.h>
16
17#include <TDF_Tool.hxx>
18
19#include <DebugBrowser.hxx>
20
21#ifdef _DEBUG
22//#define new DEBUG_NEW // by cascade
23#undef THIS_FILE
24static char THIS_FILE[] = __FILE__;
25#endif
26
27/////////////////////////////////////////////////////////////////////////////
28// COcafDoc
29
30IMPLEMENT_DYNCREATE(COcafDoc, CDocument)
31
32BEGIN_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)
48 //}}AFX_MSG_MAP
49
50END_MESSAGE_MAP()
51
52/////////////////////////////////////////////////////////////////////////////
53// COcafDoc construction/destruction
54
55COcafDoc::COcafDoc()
56{
57}
58
59COcafDoc::~COcafDoc()
60{
61}
62
63 BOOL COcafDoc::OnNewDocument()
64 {
65 if (!CDocument::OnNewDocument())
66 return FALSE;
67
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();
70
71 // Create a new Ocaf document
72 OcafApp->NewDocument("MDTV-Standard",myOcafDoc);
73 TPrsStd_AISViewer::New(myOcafDoc->Main(),myViewer);
74
75 Handle(AIS_InteractiveContext) CTX;
76 TPrsStd_AISViewer::Find(myOcafDoc->Main(), CTX);
77 CTX->SetDisplayMode(AIS_Shaded);
78 myAISContext=CTX;
79
80 // Set the maximum number of available "undo" actions
81 myOcafDoc->SetUndoLimit(10);
82
83
84 TCollection_AsciiString Message ("\
85 // Creation of a new document \n\
86 \n\
87 Handle(TOcaf_Application) OcafApp= ((COcafApp*)AfxGetApp())->GetApp(); \n\
88 \n\
89 // Creating the new document \n\
90 OcafApp->NewDocument(\"Ocaf-Sample\", myOcafDoc); \n\
91 \n\
92 // Creation of a new TPrsStd_AISViewer connected to the current V3d_Viewer\n\
93 TPrsStd_AISViewer::New(myOcafDoc->Main(),myViewer); \n\
94 \n\
95 // Setting the number of memorized undos \n\
96 myOcafDoc->SetUndoLimit(10); \n\
97 \n");
5c573e69 98
99 myCResultDialog.SetTitle("New document");
7fd59977 100 CString text(Message.ToCString());
101 myCResultDialog.SetText(text);
102
103 PathName="";
104
105 return TRUE;
106 }
107
108void COcafDoc::ActivateFrame(CRuntimeClass* pViewClass,int nCmdShow)
109{
110 POSITION position = GetFirstViewPosition();
111 while (position != (POSITION)NULL)
112 {
113 CView* pCurrentView = (CView*)GetNextView(position);
114 if(pCurrentView->IsKindOf(pViewClass) )
115 {
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);
121 }
122 }
123
124}
125
126/////////////////////////////////////////////////////////////////////////////
127// COcafDoc diagnostics
128
129#ifdef _DEBUG
130void COcafDoc::AssertValid() const
131{
132 CDocument::AssertValid();
133}
134
135void COcafDoc::Dump(CDumpContext& dc) const
136{
137 CDocument::Dump(dc);
138}
139#endif //_DEBUG
140
141/////////////////////////////////////////////////////////////////////////////
142// COcafDoc commands
143
144void COcafDoc::OnEditRedo()
145{
146 myOcafDoc->Redo();
147 myOcafDoc->CommitCommand();
148 myAISContext->UpdateCurrentViewer();
149
150 UpdateAllViews(NULL);
151
152 TCollection_AsciiString Message = TCollection_AsciiString("\
153// Redo last undoes operation \n\
154 \n\
155myOcafDoc->Redo(); \n\
156 \n\
157myOcafDoc->CommitCommand(); \n\
158 \n\
159\n");
160
5c573e69 161 myCResultDialog.SetTitle("Redo");
7fd59977 162 CString text(Message.ToCString());
163 myCResultDialog.SetText(text);
164}
165
166void COcafDoc::OnEditUndo()
167{
168 myOcafDoc->Undo();
169 myOcafDoc->CommitCommand();
170 myAISContext->UpdateCurrentViewer();
171
172 UpdateAllViews(NULL);
173
174 TCollection_AsciiString Message = TCollection_AsciiString("\
175// Undo last operation \n\
176 \n\
177myOcafDoc->Undo(); \n\
178 \n\
179myOcafDoc->CommitCommand(); \n\
180 \n\
181\n");
182
5c573e69 183 myCResultDialog.SetTitle("Undo");
7fd59977 184 CString text(Message.ToCString());
185 myCResultDialog.SetText(text);
186}
187
188void COcafDoc::OnUpdateEditRedo(CCmdUI* pCmdUI)
189{
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);
193}
194
195void COcafDoc::OnUpdateEditUndo(CCmdUI* pCmdUI)
196{
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);
200}
201
202void COcafDoc::OnCreatebox()
203{
204 EraseAll();
205 CNewBoxDlg Dlg;
206 if(Dlg.DoModal()!=IDOK) return;
207
208 Handle(TDocStd_Document) D = GetOcafDoc();
209
210 // Open a new command (for undo)
211 D->NewCommand();
212 TOcaf_Commands TSC(D->Main());
213
7fd59977 214 // Create a new box using the CNewBoxDlg Dialog parameters as attributes
576f8b11 215 TDF_Label L = TSC.CreateBox (Dlg.m_x, Dlg.m_y, Dlg.m_z, Dlg.m_w, Dlg.m_l, Dlg.m_h,
216 TCollection_ExtendedString ((Standard_ExtString )(const wchar_t* )Dlg.m_Name));
7fd59977 217
218 // Get the TPrsStd_AISPresentation of the new box TNaming_NamedShape
219 Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID());
220 // Display it
221 prs->Display(1);
222 Fit3DViews();
223 // Attach an integer attribute to L to memorize it's displayed
224 TDataStd_Integer::Set(L, 1);
225 myAISContext->UpdateCurrentViewer();
226
227 // Close the command (for undo)
228 D->CommitCommand();
229
230
231 TCollection_AsciiString Message ("\
232// Creation of a new box using Ocaf attributes \n\
233 \n\
234Handle(TDocStd_Document) D = GetOcafDoc(); \n\
235 \n\
236// Openning a new command (for undo/redo) \n\
237D->NewCommand(); \n\
238 \n\
239TOcaf_Commands TSC(D->Main()); \n\
240// Look at the TOcaf_Commands::CreateBox() function \n\
241TDF_Label L=TSC.CreateBox(m_x, m_y, m_z, m_w, m_l, m_h, Name); \n\
242 \n\
243// Set the TPrsStd_AISPresentation of the box \n\
244Handle(TPrsStd_AISPresentation) prs; \n\
245prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID()); \n\
246 \n\
247// Displaying the box \n\
248prs->Display(1); \n\
249 \n\
250// Commint the command (for undo/redo) \n\
251D->CommitCommand(); \n\
252\n");
253
5c573e69 254 myCResultDialog.SetTitle("Create box");
7fd59977 255 CString text(Message.ToCString());
256 myCResultDialog.SetText(text);
257}
258
259void COcafDoc::OnCreatecyl()
260{
261 EraseAll();
262 CNewCylDlg Dlg;
263 if(Dlg.DoModal()!=IDOK) return;
264
265 Handle(TDocStd_Document) D = GetOcafDoc();
266
267 // Open a new command (for undo)
268 D->NewCommand();
269 TOcaf_Commands TSC(D->Main());
270
7fd59977 271 // Create a new box using the CNewCylDlg Dialog parameters as attributes
576f8b11 272 TDF_Label L = TSC.CreateCyl (Dlg.m_x, Dlg.m_y, Dlg.m_z, Dlg.m_r, Dlg.m_h,
273 TCollection_ExtendedString ((Standard_ExtString )(const wchar_t* )Dlg.m_Name));
7fd59977 274
275 // Get the TPrsStd_AISPresentation of the new cylinder TNaming_NamedShape
276 Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID());
277 // Display it
278 prs->Display(1);
279 Fit3DViews();
280 // Attach an integer attribute to L to memorize it's displayed
281 TDataStd_Integer::Set(L, 1);
282 myAISContext->UpdateCurrentViewer();
283
284 // Close the command (for undo)
285 D->CommitCommand();
286
287
288 TCollection_AsciiString Message ("\
289// Creation of a new cylinder using Ocaf attributes \n\
290 \n\
291Handle(TDocStd_Document) D = GetOcafDoc(); \n\
292 \n\
293// Openning a new command (for undo/redo) \n\
294D->NewCommand(); \n\
295 \n\
296TOcaf_Commands TSC(D->Main()); \n\
297// Look at the TOcaf_Commands::CreateCyl() function \n\
298TDF_Label L=TSC.CreateCyl(m_x, m_y, m_z, m_r, m_h, Name); \n\
299 \n\
300// Set the TPrsStd_AISPresentation of the cylinder \n\
301Handle(TPrsStd_AISPresentation) prs; \n\
302prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID()); \n\
303 \n\
304// Displaying the cylinder \n\
305prs->Display(1); \n\
306 \n\
307// Commint the command (for undo/redo) \n\
308D->CommitCommand(); \n\
309\n");
310
5c573e69 311 myCResultDialog.SetTitle("Create cylinder");
7fd59977 312 CString text(Message.ToCString());
313 myCResultDialog.SetText(text);
314}
315
316void COcafDoc::OnModify()
317{
318 // Get the selected interactive object
319 myAISContext->InitCurrent();
320 Handle(AIS_InteractiveObject) curAISObject = myAISContext->Current();
321
322
323 // Get the main label of the selected object
324 Handle(TPrsStd_AISPresentation) ObjectPrs =
325 Handle(TPrsStd_AISPresentation)::DownCast(curAISObject->GetOwner());
326 TDF_Label LabObject = ObjectPrs->Label();
327
328 // Get the TFunction_Function attribute of the selected object
329 Handle(TFunction_Function) TFF;
330 if ( !LabObject.FindAttribute(TFunction_Function::GetID(),TFF) )
331 {
576f8b11 332 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Object cannot be modify.", L"Modification", MB_ICONEXCLAMATION);
7fd59977 333 return;
334 }
335 // Get the Standard_GUID of the TFunction_FunctionDriver of the selected object TFunction_Function attribute
336 Standard_GUID myDriverID=TFF->GetDriverGUID();
337
338 Handle(TDocStd_Document) D = GetOcafDoc();
339 TFunction_Logbook log;
340
341 TCollection_AsciiString Message("\
342// Modification and recomputation of the selected object \n\
343 \n\
344Handle(TDocStd_Document) D = GetOcafDoc(); \n\
345 \n\
346// Getting the TPrsStd_AISPresentation of the selected object \n\
347Handle(TPrsStd_AISPresentation) ObjectPrs = \n\
348 Handle(TPrsStd_AISPresentation)::DownCast(curAISObject->GetOwner()); \n\
349 \n\
350// Getting the Label of the selected object using the TPrsStd_AISPresentation \n\
351TDF_Label LabObject = ObjectPrs->Label(); \n\
352 \n\
353// Getting the TFunction_FunctionDriver ID attached to this label \n\
354Handle(TFunction_Function) TFF; \n\
355\n");
356 TCollection_AsciiString Suite;
357
358 // Case of a box created with the box function driver
359 if(myDriverID==TOcafFunction_BoxDriver::GetID())
360 {
361 CNewBoxDlg Dlg;
362 Standard_Real x, y, z, w, l, h;
363
364 // Get the attributes values of the current box
365 Handle(TDataStd_Real) curReal;
366 LabObject.FindChild(1).FindAttribute(TDataStd_Real::GetID(),curReal);
367 w=curReal->Get();
368 LabObject.FindChild(2).FindAttribute(TDataStd_Real::GetID(),curReal);
369 l=curReal->Get();
370 LabObject.FindChild(3).FindAttribute(TDataStd_Real::GetID(),curReal);
371 h=curReal->Get();
372 LabObject.FindChild(4).FindAttribute(TDataStd_Real::GetID(),curReal);
373 x=curReal->Get();
374 LabObject.FindChild(5).FindAttribute(TDataStd_Real::GetID(),curReal);
375 y=curReal->Get();
376 LabObject.FindChild(6).FindAttribute(TDataStd_Real::GetID(),curReal);
377 z=curReal->Get();
378 Handle(TDataStd_Name) stdName;
379 LabObject.FindAttribute(TDataStd_Name::GetID(),stdName);
380
381 // Initialize the dialog box with the values of the current box
382 Dlg.InitFields(x, y, z, w, l, h, stdName->Get());
383
384 if(Dlg.DoModal()!=IDOK) return;
385
386 // Open a new command (for undo)
387 D->NewCommand();
388
7fd59977 389 // Modify the box
390 TOcaf_Commands TSC(LabObject);
576f8b11 391 TSC.ModifyBox (Dlg.m_x, Dlg.m_y, Dlg.m_z, Dlg.m_w, Dlg.m_l, Dlg.m_h,
392 TCollection_ExtendedString ((Standard_ExtString )(const wchar_t* )Dlg.m_Name), log);
7fd59977 393
394 // Get the presentation of the box, display it and set it selected
395 Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID());
396 TDataStd_Integer::Set(LabObject, 1);
397 prs->Display(1);
398 myAISContext->UpdateCurrentViewer();
399 // Close the command (for undo)
400 D->CommitCommand();
401
402 Message+=("\
403 \n\
404// In this case the TFunction_FunctionDriver ID is a BoxDriver \n\
405if(myDriverID==TOcafFunction_BoxDriver::GetID()){ \n\
406 \n\
407// Getting values of box attributes \n\
408Handle(TDataStd_Real) curReal; \n\
409LabObject.FindChild(1).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
410w=curReal->Get(); \n\
411LabObject.FindChild(2).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
412l=curReal->Get(); \n\
413LabObject.FindChild(3).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
414h=curReal->Get(); \n\
415LabObject.FindChild(4).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
416x=curReal->Get(); \n\
417LabObject.FindChild(5).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
418y=curReal->Get(); \n\
419LabObject.FindChild(6).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
420z=curReal->Get(); \n\
421Handle(TDataStd_Name) stdName; \n\
422LabObject.FindAttribute(TDataStd_Name::GetID(),stdName); \n\
423 \n\
424// Openning a new command \n\
425D->NewCommand(); \n\
426 \n\
427TOcaf_Commands TSC(LabObject); \n\
428// Look at the TOcaf_Commands::ModifyBox() function \n\
429TSC.ModifyBox(m_x, m_y, m_z, m_w, m_l, m_h, Name); \n\
430 \n\
431// Set the TPrsStd_AISPresentation of the box \n\
432Handle(TPrsStd_AISPresentation) prs; \n\
433prs= TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID()); \n\
434 \n\
435// Display the box \n\
436prs->Display(1); \n\
437 \n\
438// Commit the command \n\
439D->CommitCommand(); \n\
440} \n\
441\n");
5c573e69 442
443 myCResultDialog.SetTitle("Modify Box");
7fd59977 444 }
445 // Case of a cylinder created with the box function driver
446 else if(myDriverID==TOcafFunction_CylDriver::GetID())
447 {
448 CNewCylDlg Dlg;
449 Standard_Real x, y, z, r, h;
450
451 // Get the attributes values of the current box
452 Handle(TDataStd_Real) curReal;
453 LabObject.FindChild(1).FindAttribute(TDataStd_Real::GetID(),curReal);
454 r=curReal->Get();
455 LabObject.FindChild(2).FindAttribute(TDataStd_Real::GetID(),curReal);
456 h=curReal->Get();
457 LabObject.FindChild(3).FindAttribute(TDataStd_Real::GetID(),curReal);
458 x=curReal->Get();
459 LabObject.FindChild(4).FindAttribute(TDataStd_Real::GetID(),curReal);
460 y=curReal->Get();
461 LabObject.FindChild(5).FindAttribute(TDataStd_Real::GetID(),curReal);
462 z=curReal->Get();
463 Handle(TDataStd_Name) stdName;
464 LabObject.FindAttribute(TDataStd_Name::GetID(),stdName);
465
466 // Initialize the dialog cylinder with the values of the current cylinder
467 Dlg.InitFields(x, y, z, r, h, stdName->Get());
468
469 if(Dlg.DoModal()!=IDOK) return;
470
471 // Open a new command (for undo)
472 D->NewCommand();
473
7fd59977 474 // Modify the cylinder
475 TOcaf_Commands TSC(LabObject);
576f8b11 476 TSC.ModifyCyl (Dlg.m_x, Dlg.m_y, Dlg.m_z, Dlg.m_r, Dlg.m_h,
477 TCollection_ExtendedString ((Standard_ExtString )(const wchar_t* )Dlg.m_Name), log);
7fd59977 478
479 // Get the presentation of the cylinder, display it and set it selected
480 Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID());
481 TDataStd_Integer::Set(LabObject, 1);
482 prs->Display(1);
483 myAISContext->UpdateCurrentViewer();
484 // Close the command (for undo)
485 D->CommitCommand();
486
487 Message+=("\
488 \n\
489// In this case the TFunction_FunctionDriver ID is a CylDriver \n\
490if(myDriverID==TOcafFunction_CylDriver::GetID()){ \n\
491 \n\
492// Getting values of box cylinder \n\
493Handle(TDataStd_Real) curReal; \n\
494LabObject.FindChild(1).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
495r=curReal->Get(); \n\
496LabObject.FindChild(2).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
497h=curReal->Get(); \n\
498LabObject.FindChild(3).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
499x=curReal->Get(); \n\
500LabObject.FindChild(4).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
501y=curReal->Get(); \n\
502LabObject.FindChild(5).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
503z=curReal->Get(); \n\
504Handle(TDataStd_Name) stdName; \n\
505LabObject.FindAttribute(TDataStd_Name::GetID(),stdName); \n\
506 \n\
507// Openning a new command \n\
508D->NewCommand(); \n\
509 \n\
510TOcaf_Commands TSC(LabObject); \n\
511// Look at the TOcaf_Commands::ModifyCyl() function \n\
512TSC.ModifyCyl(m_x, m_y, m_z, m_r, m_h, Name); \n\
513 \n\
514// Set the TPrsStd_AISPresentation of the cylinder \n\
515Handle(TPrsStd_AISPresentation) prs; \n\
516prs= TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID()); \n\
517 \n\
518// Display the cylinder \n\
519prs->Display(1); \n\
520 \n\
521// Commit the command \n\
522D->CommitCommand(); \n\
523} \n\
524\n");
5c573e69 525
526 myCResultDialog.SetTitle("Modify cylinder");
7fd59977 527 }
528 // Case of a cut solid created with the cut function driver
529 else if(myDriverID==TOcafFunction_CutDriver::GetID())
530 {
531 // Open a new command (for undo)
532 D->NewCommand();
533
534 // Get the reference of the Original object used to make the cut object,
535 // this reference is here attached to the first child of the cut object label
536 Handle(TDF_Reference) OriginalRef;
537 LabObject.FindChild(1).FindAttribute(TDF_Reference::GetID(),OriginalRef);
538
539 // Get the presentation of the Original object
540 Handle(TPrsStd_AISPresentation) OriginalPrs= TPrsStd_AISPresentation::Set(OriginalRef->Get(), TNaming_NamedShape::GetID());
541
542 // Get the reference of the Tool object used to make the cut object,
543 // this reference is here attached to the second child of the cut object label
544 Handle(TDF_Reference) ToolRef;
545 LabObject.FindChild(2).FindAttribute(TDF_Reference::GetID(),ToolRef);
546 TDF_Label ToolLab=ToolRef->Get();
547
548
549 // Get the presentation of the Tool object
550 Handle(TPrsStd_AISPresentation) ToolPrs= TPrsStd_AISPresentation::Set(ToolLab, TNaming_NamedShape::GetID());
551
552 // Display the Original object and the Tool object, erase the cut object.
553 TDataStd_Integer::Set(OriginalRef->Get(), 1);
554 OriginalPrs->Display(1);
555 TDataStd_Integer::Set(ToolLab, 1);
556 ToolPrs->Display(1);
557 TDataStd_Integer::Set(LabObject, 0);
558 ObjectPrs->Erase(1);
559 myAISContext->UpdateCurrentViewer();
560
561 // In this we decided to modify the tool object which is a cylinder,
562 // so we open the cylinder parameters dialog box
563 CNewCylDlg Dlg;
564 Standard_Real x, y, z, h, r;
565
566 // Get the attributes values of the tool cylinder
567 Handle(TDataStd_Real) curReal;
568 ToolLab.FindChild(1).FindAttribute(TDataStd_Real::GetID(),curReal);
569 r=curReal->Get();
570 ToolLab.FindChild(2).FindAttribute(TDataStd_Real::GetID(),curReal);
571 h=curReal->Get();
572 ToolLab.FindChild(3).FindAttribute(TDataStd_Real::GetID(),curReal);
573 x=curReal->Get();
574 ToolLab.FindChild(4).FindAttribute(TDataStd_Real::GetID(),curReal);
575 y=curReal->Get();
576 ToolLab.FindChild(5).FindAttribute(TDataStd_Real::GetID(),curReal);
577 z=curReal->Get();
578 Handle(TDataStd_Name) stdName;
579 ToolLab.FindAttribute(TDataStd_Name::GetID(),stdName);
580
581 // Initialize the dialog box with the values of the tool cylinder
582 Dlg.InitFields(x, y, z, r, h, stdName->Get());
583
584 if(Dlg.DoModal()!=IDOK)
585 {
586 D->AbortCommand();
587 myAISContext->UpdateCurrentViewer();
588 return;
589 }
7fd59977 590
591 // Modify the cylinder
592 TOcaf_Commands ToolTSC(ToolLab);
576f8b11 593 ToolTSC.ModifyCyl (Dlg.m_x, Dlg.m_y, Dlg.m_z, Dlg.m_r, Dlg.m_h,
594 TCollection_ExtendedString ((Standard_ExtString )(const wchar_t* )Dlg.m_Name), log);
7fd59977 595
596 // Redisplay the modified Tool object
597 TDataStd_Integer::Set(ToolLab, 1);
598 ToolPrs->Display(1);
599 myAISContext->UpdateCurrentViewer();
600 Sleep(1000);
601
602 // Get the TOcafFunction_CutDriver using its Standard_GUID in the TFunction_DriverTable
603 Handle(TOcafFunction_CutDriver) myCutDriver;
cc1d74e2 604 if (TFunction_DriverTable::Get()->FindDriver(myDriverID, myCutDriver))
605 myCutDriver->Init(LabObject);
7fd59977 606
607 // Recompute the cut object if it must be (look at the MustExecute function code)
608// if (myCutDriver->MustExecute(log))
609// {
610 log.SetTouched(LabObject);
611 if(myCutDriver->Execute(log))
576f8b11 612 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Recompute failed", L"Modify cut", MB_ICONEXCLAMATION);
7fd59977 613// }
614
615 // Erase the Original object and the Tool objectedisplay the modified Tool object
616 TDataStd_Integer::Set(ToolLab, 0);
617 ToolPrs->Erase(0);
618 TDataStd_Integer::Set(OriginalRef->Get(), 0);
619 OriginalPrs->Erase(0);
620 ObjectPrs=TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID());
621 TDataStd_Integer::Set(LabObject, 1);
622 ObjectPrs->Display(1);
623 myAISContext->UpdateCurrentViewer();
624 // Close the command (for undo)
625 D->CommitCommand();
626
627 Message+=("\
628 \n\
629// In this case the TFunction_FunctionDriver ID is a CutDriver \n\
630if(myDriverID==TOcafFunction_CutDriver::GetID()){ \n\
631 \n\
632// Getting values of cut attributes (which are reference to the shapes)\n\
633Handle(TDF_Reference) OriginalRef; \n\
634LabObject.FindChild(1).FindAttribute(TDF_Reference::GetID(),OriginalRef); \n\
635Handle(TDF_Reference) ToolRef; \n\
636LabObject.FindChild(2).FindAttribute(TDF_Reference::GetID(),ToolRef); \n\
637 \n\
638// Getting the label of the tool shape (to modify it)\n\
639TDF_Label ToolLab=ToolRef->Get(); \n\
640 \n\
641TOcaf_Commands TSC(ToolLab); \n\
642// Look at the TOcaf_Commands::ModifyBox() function \n\
643TSC.ModifyBox(m_x, m_y, m_z, m_w, m_l, m_h, Name); \n\
644 \n\
645// Getting the TOcafFunction_CutDriver used to create the cut\n\
646Handle(TOcafFunction_CutDriver) myCutDriver; \n\
647TFunction_DriverTable::Get()->FindDriver(myDriverID, myCutDriver); \n\
648 \n\
649// Recompute the cut if it must be (if an attribute was modified)\n\
650if (myCutDriver->MustExecute(log)) { \n\
651 log.SetTouched(LabObject); \n\
652 myCutDriver->Execute(log) \n\
653} \n\
654Handle(TPrsStd_AISPresentation) prs; \n\
655 \n\
656// Setting the TPrsStd_AISPresentation of the cut object\n\
657prs= TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID()); \n\
658 \n\
659// Display the TPrsStd_AISPresentation of the cut object\n\
660prs->Display(1); \n\
661 \n\
662// Commit the command\n\
663D->CommitCommand(); \n\
664} \n\
665\n");
5c573e69 666
667 myCResultDialog.SetTitle("Modify Cut");
7fd59977 668 }
669 else
670 {
576f8b11 671 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"No associated function driver", L"Modify", MB_OK);
7fd59977 672 }
673
674 CString text(Message.ToCString());
675 myCResultDialog.SetText(text);
676}
677
678void COcafDoc::OnUpdateModify(CCmdUI* pCmdUI)
679{
680 // Disable the "modify" button if there is no selected object or several selected objects
681 myAISContext->InitCurrent();
682 if(myAISContext->NbCurrents()!=1)
683 {
684 pCmdUI->Enable(Standard_False);
685 return;
686 }
687
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();
694
695
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) );
699 }
700 else
701 pCmdUI->Enable(FALSE);
702}
703
704
705void COcafDoc::OnCut()
706{
707 EraseAll();
708 Handle(TDocStd_Document) D = GetOcafDoc();
709 TDF_Label L = D->Main();
710
711 TOcaf_Commands TSC(L);
712
713 // Open a new command (for undo)
714 D->NewCommand();
715
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);
721 prs1->Display(1);
722 Fit3DViews();
723
724 // Wait a second to see the construction
725 Sleep(500);
726
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);
732 prs2->Display(1);
733 Fit3DViews();
734
735 Sleep(1000);
736
737 // Cut the boxes
738 L=TSC.Cut(L1, L2);
739 Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID());
740
741 // Erase the two boxes and display the cut object
742 TDataStd_Integer::Set(L1, 0);
743 prs1->Erase(0);
744 TDataStd_Integer::Set(L2, 0);
745 prs2->Erase(0);
746 TDataStd_Integer::Set(L, 1);
747 prs->Display(1);
748 myAISContext->UpdateCurrentViewer();
749
750 // Close the cut operation command (for undo)
751 D->CommitCommand();
752
753
754 TCollection_AsciiString Message ("\
755// Cut operation between a cylinder and a box \n\
756 \n\
757Handle(TDocStd_Document) D = GetOcafDoc(); \n\
758TDF_Label L = D->Main(); \n\
759 \n\
760// Openning a new command\n\
761D->NewCommand(); \n\
762 \n\
763TOcaf_Commands TSC(D->Main()); \n\
764 \n\
765// Create a box \n\
766// Look at the TOcaf_Commands::CreateBox() function \n\
767TDF_Label L1=TSC.CreateBox(-12, 0, 10, 24, 20, 20, '\"'Box'\"'); \n\
768// Look at the TOcaf_Commands::Cut() function \n\
769 \n\
770// Create a cylinder \n\
771// Look at the TOcaf_Commands::CreateCyl() function \n\
772// Create two boxes \n\
773TDF_Label L2=TSC.CreateCyl(0, 0, 0, 10, 20, '\"'Cylinder'\"'); \n\
774 \n\
775// Cut the cylinder with the box \n\
776L=TSC.Cut(L1, L2); \n\
777Handle(TPrsStd_AISPresentation) prs; \n\
778 \n\
779// Setting the TPrsStd_AISPresentation of the cut object\n\
780prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID()); \n\
781 \n\
782// Displaying the TPrsStd_AISPresentation of the cut object\n\
783prs->Display(1); \n\
784 \n\
785// Commit the command\n\
786D->CommitCommand(); \n\
787\n");
788
5c573e69 789 myCResultDialog.SetTitle("Cut operation");
7fd59977 790 CString text(Message.ToCString());
791 myCResultDialog.SetText(text);
792}
793
794
795void COcafDoc::Fit3DViews()
796{
797 POSITION position = GetFirstViewPosition();
798 while (position != (POSITION)NULL)
799 {
800 CView* pCurrentView = (CView*)GetNextView(position);
801 if(pCurrentView->IsKindOf( RUNTIME_CLASS( OCC_3dView ) ) )
802 {
803 ASSERT_VALID(pCurrentView);
804 OCC_3dView* aOCC_3dView = (OCC_3dView*)pCurrentView;
805 aOCC_3dView->FitAll();
806 }
807 }
808
809}
810
811void COcafDoc::OnObjectDelete()
812{
813 Handle(TDocStd_Document) D = GetOcafDoc();
814
815 D->NewCommand();
816
817 AIS_SequenceOfInteractive aSequence;
818 for(myAISContext->InitCurrent();
819 myAISContext->MoreCurrent();
820 myAISContext->NextCurrent())
821 aSequence.Append(myAISContext->Current());
822
823 for(int iter=1;iter <=aSequence.Length();iter++)
824 {
825 if (myAISContext->DisplayStatus(aSequence(iter)) == AIS_DS_Displayed)
826 {
827 Handle(TPrsStd_AISPresentation) CurrentPrs
828 = Handle(TPrsStd_AISPresentation)::DownCast(aSequence(iter)->GetOwner());
829 TDataStd_Integer::Set(CurrentPrs->Label(), 0);
830 CurrentPrs->Erase(1);
831 }
832 }
833
834 D->CommitCommand();
835 myAISContext->UpdateCurrentViewer();
836
837 TCollection_AsciiString Message ("\
838 // Delete selected object \n\
839 \n\
840 Handle(TDocStd_Document) D = GetOcafDoc(); \n\
841 \n\
842 // Openning a new command\n\
843 D->NewCommand(); \n\
844 \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\
848 \n\
849 // Erasing the TPrsStd_AISPresentation of the selected object\n\
850 CurrentPrs->Erase(1); \n\
851 \n\
852 // Commit the command\n\
853 D->CommitCommand(); \n\
854 \n");
5c573e69 855
856 myCResultDialog.SetTitle("Delete");
7fd59977 857 CString text(Message.ToCString());
858 myCResultDialog.SetText(text);
859 }
860
861 void COcafDoc::OnUpdateObjectDelete(CCmdUI* pCmdUI)
862 {
863 myAISContext->InitCurrent();
864 pCmdUI->Enable (myAISContext->MoreCurrent());
865 }
866
867 void COcafDoc::DisplayPrs()
868 {
869 TDF_Label LabSat = myOcafDoc->Main();
870
871 for (TDF_ChildIterator it(LabSat); it.More(); it.Next())
872 {
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;
877
878 // To know if the object was displayed
879 if (L.FindAttribute(TDataStd_Integer::GetID(), TDI))
880 if(!TDI->Get()) continue;
881
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);
886 prs->Display(1);
887 }
888
889 myAISContext->UpdateCurrentViewer();
890}
891
892void COcafDoc::OnCloseDocument()
893{
894 Handle(TOcaf_Application) OcafApp = ((COcafApp*)AfxGetApp())->GetApp();
895 OcafApp->Close(myOcafDoc);
896 CDocument::OnCloseDocument();
897}
898
899void COcafDoc::OnFileSaveAs()
900{
576f8b11 901 const wchar_t* SPathName = PathName;
902 TCollection_ExtendedString TPathName ((Standard_ExtString )SPathName);
7fd59977 903
904 CString Filter;
905
906 if (TPathName.SearchFromEnd(".xml") > 0){
cc1d74e2 907 Filter = "OCAFSample(XML) (*.xml)|*.xml|OCAFSample(STD) (*.std)|*.std|OCAFSample(Binary) (*.cbf)|*.cbf||";
7fd59977 908 }
909 else if (TPathName.SearchFromEnd(".cbf") > 0){
cc1d74e2 910 Filter = "OCAFSample(Binary) (*.cbf)|*.cbf|OCAFSample(STD) (*.std)|*.std|OCAFSample(XML) (*.xml)|*.xml||";
7fd59977 911 }
912 else{
cc1d74e2 913 Filter = "OCAFSample(STD) (*.std)|*.std|OCAFSample(XML) (*.xml)|*.xml|OCAFSample(Binary) (*.cbf)|*.cbf||";
7fd59977 914 }
915
916 CFileDialog dlg(FALSE,
576f8b11 917 L"std",
7fd59977 918 GetTitle(),
919 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
920 Filter,
7fd59977 921 NULL );
922
923
924 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp();
925 if (dlg.DoModal() != IDOK) return;
926
927 SetTitle(dlg.GetFileTitle());
928
929 CWaitCursor aWaitCursor;
930 CString CSPath = dlg.GetPathName();
931
7fd59977 932 cout << "Save As " << CSPath << endl;
933 PathName=CSPath;
576f8b11 934 const wchar_t* SPath = CSPath;
935 TCollection_ExtendedString TPath ((Standard_ExtString )SPath);
7fd59977 936
937 if (TPath.SearchFromEnd(".xml") > 0)
938 {
939 // The document must be saved in XML format
940 myOcafDoc->ChangeStorageFormat("XmlOcaf");
941 }
942 else if (TPath.SearchFromEnd(".cbf") > 0)
943 {
944 // The document must be saved in binary format
945 myOcafDoc->ChangeStorageFormat("BinOcaf");
946 }
947 else
948 {
949 // The document must be saved in standard format
950 myOcafDoc->ChangeStorageFormat("MDTV-Standard");
951 }
952
953 try
954 {
955 // Saves the document in the current application
956 m_App->SaveAs(myOcafDoc,TPath);
957 }
958 catch(...)
959 {
576f8b11 960 AfxMessageBox (L"Error! The file wasn't saved.");
7fd59977 961 return;
962 }
963// // save the document in the current application
964// m_App->SaveAs(myOcafDoc,TPath);
965
966 SetPathName(SPath);
967
968 TCollection_AsciiString Message = TCollection_AsciiString("\
969// Storing the document as \n\
970 \n\
971Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp(); \n\
972 \n\
973// Saving current OCAF document at TPath \n\
974m_App->SaveAs(myOcafDoc,(TCollection_ExtendedString) TPath); \n\
975\n");
976
5c573e69 977 myCResultDialog.SetTitle("Save a document");
7fd59977 978 CString text(Message.ToCString());
979 myCResultDialog.SetText(text);
980}
981
982void COcafDoc::OnFileSave()
983{
984 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp();
985
986
987 if (myOcafDoc.IsNull())
988 {
576f8b11 989 AfxMessageBox (L"Error during saving! Empty document.");
7fd59977 990 return;
991 }
992
993 if(PathName!="")
994 {
576f8b11 995 const wchar_t* SPath = PathName;
996 TCollection_ExtendedString TPath ((Standard_ExtString )SPath);
7fd59977 997
998 if (TPath.SearchFromEnd(".xml") > 0)
999 {
1000 // The document must be saved in XML format
1001 myOcafDoc->ChangeStorageFormat("XmlOcaf");
1002 }
1003 else if (TPath.SearchFromEnd(".cbf") > 0)
1004 {
1005 // The document must be saved in binary format
1006 myOcafDoc->ChangeStorageFormat("BinOcaf");
1007 }
1008 else
1009 {
1010 // The document must be saved in standard format
1011 myOcafDoc->ChangeStorageFormat("MDTV-Standard");
1012 }
1013
1014 try
1015 {
1016 // Saves the document in the current application
1017 m_App->SaveAs(myOcafDoc,TPath);
1018 }
1019 catch(...)
1020 {
576f8b11 1021 AfxMessageBox (L"Error! The file wasn't saved.");
7fd59977 1022 return;
1023 }
1024
1025 TCollection_AsciiString Message = TCollection_AsciiString("\
1026// Storing the document \n\
1027 \n\
1028Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp(); \n\
1029 \n\
1030// Saving current OCAF document at TPath \n\
1031m_App->SaveAs(myOcafDoc,(TCollection_ExtendedString) TPath); \n\
1032\n");
1033
5c573e69 1034 myCResultDialog.SetTitle("Save a document");
7fd59977 1035 CString text(Message.ToCString());
1036 myCResultDialog.SetText(text);
1037 return;
1038 }
1039
1040 CFileDialog dlg(FALSE,
576f8b11 1041 L"std",
7fd59977 1042 GetTitle(),
1043 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
576f8b11 1044 L"OCAFSample(STD) (*.std)|*.std|OCAFSample(XML) (*.xml)|*.xml|OCAFSample(Binary) (*.cbf)|*.cbf||",
7fd59977 1045 NULL );
1046
1047 if (dlg.DoModal() != IDOK) return;
1048
1049 SetTitle(dlg.GetFileTitle());
1050
1051 CWaitCursor aWaitCursor;
1052 CString CSPath = dlg.GetPathName();
1053
576f8b11 1054 const wchar_t* SPath = CSPath;
1055 TCollection_ExtendedString TPath ((Standard_ExtString )SPath);
7fd59977 1056
1057 // Choose storage format
1058 if (TPath.SearchFromEnd(".xml") > 0)
1059 {
1060 // The document must be saved in XML format
1061 myOcafDoc->ChangeStorageFormat("XmlOcaf");
1062 }
1063 else if (TPath.SearchFromEnd(".cbf") > 0)
1064 {
1065 // The document must be saved in binary format
1066 myOcafDoc->ChangeStorageFormat("BinOcaf");
1067 }
1068 else
1069 {
1070 // The document must be saved in standard format
1071 myOcafDoc->ChangeStorageFormat("Ocaf-Sample");
1072 }
1073
1074 try
1075 {
1076 // Saves the document in the current application
1077 m_App->SaveAs(myOcafDoc,TPath);
1078 }
1079 catch(...)
1080 {
576f8b11 1081 AfxMessageBox (L"Error! The file wasn't saved.");
7fd59977 1082 return;
1083 }
1084
7fd59977 1085 SetPathName(SPath);
1086 PathName=CSPath;
1087
1088
1089 TCollection_AsciiString Message = TCollection_AsciiString("\
1090// Storing the document as \n\
1091 \n\
1092Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp(); \n\
1093 \n\
1094// Saving current OCAF document at TPath \n\
1095m_App->SaveAs(myOcafDoc,(TCollection_ExtendedString) TPath); \n\
1096\n");
1097
5c573e69 1098 myCResultDialog.SetTitle("Save a document");
7fd59977 1099 CString text(Message.ToCString());
1100 myCResultDialog.SetText(text);
1101}
1102
47162471 1103BOOL COcafDoc::OnOpenDocument(LPCTSTR lpszPathName)
7fd59977 1104{
47162471 1105 if (!CDocument::OnOpenDocument(lpszPathName))
1106 {
1107 return FALSE;
1108 }
7fd59977 1109
47162471 1110 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp();
7fd59977 1111
47162471 1112 CWaitCursor aWaitCursor;
1113 PathName = lpszPathName;
7fd59977 1114
47162471 1115 const wchar_t* aPathName = lpszPathName;
1116 TCollection_ExtendedString anOccPathName ((Standard_ExtString)aPathName);
1117
1118 // Open the document in the current application
5c573e69 1119 //PCDM_ReaderStatus RS = m_App->Open(TPath,myOcafDoc);
47162471 1120 m_App->Open(anOccPathName, myOcafDoc);
5c573e69 1121 //CDF_RetrievableStatus RS = m_App->Open(TPath,myOcafDoc);
7fd59977 1122
47162471 1123 // Connect the document CAF (myDoc) with the AISContext (myAISContext)
1124 TPrsStd_AISViewer::New (myOcafDoc->Main(), myViewer);
1125 myOcafDoc->SetUndoLimit (10);
7fd59977 1126
47162471 1127 Handle(AIS_InteractiveContext) aContext;
1128 TPrsStd_AISViewer::Find (myOcafDoc->Main(), aContext);
1129 aContext->SetDisplayMode (AIS_Shaded);
1130 myAISContext = aContext;
7fd59977 1131
47162471 1132 // Display the presentations (which was not stored in the document)
1133 DisplayPrs();
7fd59977 1134
47162471 1135 TCollection_AsciiString Message = TCollection_AsciiString("\
7fd59977 1136// Retrieve a document \n\
1137 \n\
1138 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp(); \n\
1139 \n\
1140// Openning the OCAF document from the TPath file\n\
1141m_App->Open((TCollection_ExtendedString) TPath,myOcafDoc); \n\
1142 \n\
1143// Creation of a new TPrsStd_AISViewer connected to the current V3d_Viewer\n\
1144TPrsStd_AISViewer::New(myOcafDoc->Main(),myViewer); \n\
1145 \n\
1146// Setting the number of memorized undos \n\
1147myOcafDoc->SetUndoLimit(10); \n\
1148 \n\
1149\n");
5c573e69 1150
47162471 1151 myCResultDialog.SetTitle ("Open a document");
1152 CString text (Message.ToCString());
1153 myCResultDialog.SetText (text);
7fd59977 1154
47162471 1155 return TRUE;
7fd59977 1156
1157}
1158
1159
1160void COcafDoc::EraseAll()
1161{
1162 myOcafDoc->NewCommand();
1163
1164 TDF_Label LabSat = myOcafDoc->Main();
1165
1166 for (TDF_ChildIterator it(LabSat); it.More(); it.Next())
1167 {
1168 TDF_Label L = it.Value();
1169 Handle(TNaming_NamedShape) TNS;
1170 if (!L.FindAttribute(TNaming_NamedShape::GetID(), TNS)) continue;
1171 Handle(TDataStd_Integer) TDI;
1172
1173 // To know if the object was displayed
1174 if (L.FindAttribute(TDataStd_Integer::GetID(), TDI))
1175 if(!TDI->Get()) continue;
1176
1177 Handle(TPrsStd_AISPresentation) prs;
1178 if (!L.FindAttribute(TPrsStd_AISPresentation::GetID(),prs))
1179 prs = TPrsStd_AISPresentation::Set(L,TNaming_NamedShape::GetID());
1180 prs->SetColor(Quantity_NOC_ORANGE);
1181 prs->Erase(1);
1182 }
1183
1184 myAISContext->UpdateCurrentViewer();
1185
1186 myOcafDoc->CommitCommand();
1187}
1188
1189void COcafDoc::Popup(const Standard_Integer x,
1190 const Standard_Integer y ,
1191 const Handle(V3d_View)& aView )
1192{
1193 Standard_Integer PopupMenuNumber=0;
1194 myAISContext->InitCurrent();
1195 if (myAISContext->MoreCurrent())
1196 PopupMenuNumber=1;
1197
1198 CMenu menu;
1199 VERIFY(menu.LoadMenu(IDR_Popup3D));
1200 CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber);
1201
1202 ASSERT(pPopup != NULL);
1203 if (PopupMenuNumber == 1) // more than 1 object.
1204 {
1205 bool OneOrMoreInShading = false;
1206 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
1207 if (myAISContext->IsDisplayed(myAISContext->Current(),1)) OneOrMoreInShading=true;
1208 if(!OneOrMoreInShading)
1209 pPopup->EnableMenuItem(5, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
1210 }
1211
1212 POINT winCoord = { x , y };
1213 Handle(WNT_Window) aWNTWindow=
1214 Handle(WNT_Window)::DownCast(aView->Window());
1215 ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord);
1216 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y ,
1217 AfxGetMainWnd());
1218
1219
1220}
1221
1222
1223//void COcafDoc::OnDfbr()
1224//{
1225// // TODO: Add your command handler code here
1226// DebugBrowser::DFBrowser(myOcafDoc);
1227//
1228//}