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