5b6872df45969568e800a226ff2c2c32db22bf89
[occt.git] / samples / mfc / standard / 06_Ocaf / src / OcafDoc.cpp
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
24 static char THIS_FILE[] = __FILE__;
25 #endif
26
27 /////////////////////////////////////////////////////////////////////////////
28 // COcafDoc
29
30 IMPLEMENT_DYNCREATE(COcafDoc, CDocument)
31
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)
48         //}}AFX_MSG_MAP
49
50 END_MESSAGE_MAP()
51
52 /////////////////////////////////////////////////////////////////////////////
53 // COcafDoc construction/destruction
54
55 COcafDoc::COcafDoc()
56 {
57 }
58
59 COcafDoc::~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("BinOcaf",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(\"BinOcaf\", 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");
98
99   myCResultDialog.SetTitle("New document");
100         CString text(Message.ToCString());
101         myCResultDialog.SetText(text);
102  
103         PathName="";
104  
105         return TRUE;
106  }
107
108 void 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
130 void COcafDoc::AssertValid() const
131 {
132         CDocument::AssertValid();
133 }
134
135 void COcafDoc::Dump(CDumpContext& dc) const
136 {
137         CDocument::Dump(dc);
138 }
139 #endif //_DEBUG
140
141 /////////////////////////////////////////////////////////////////////////////
142 // COcafDoc commands
143
144 void 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\
155 myOcafDoc->Redo(); \n\
156  \n\
157 myOcafDoc->CommitCommand(); \n\
158  \n\
159 \n");
160
161         myCResultDialog.SetTitle("Redo");
162         CString text(Message.ToCString());
163         myCResultDialog.SetText(text);
164 }
165
166 void 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\
177 myOcafDoc->Undo(); \n\
178  \n\
179 myOcafDoc->CommitCommand(); \n\
180  \n\
181 \n");
182
183         myCResultDialog.SetTitle("Undo");
184         CString text(Message.ToCString());
185         myCResultDialog.SetText(text);
186 }
187
188 void 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
195 void 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
202 void 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         // Create a new box using the CNewBoxDlg Dialog parameters as attributes
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));
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\
234 Handle(TDocStd_Document) D = GetOcafDoc(); \n\
235  \n\
236 //  Openning a new command (for undo/redo) \n\
237 D->NewCommand(); \n\
238  \n\
239 TOcaf_Commands TSC(D->Main()); \n\
240 // Look at the TOcaf_Commands::CreateBox() function \n\
241 TDF_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\
244 Handle(TPrsStd_AISPresentation) prs; \n\
245 prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID()); \n\
246  \n\
247 //  Displaying the box \n\
248 prs->Display(1); \n\
249  \n\
250 //  Commint the command (for undo/redo) \n\
251 D->CommitCommand(); \n\
252 \n");
253
254         myCResultDialog.SetTitle("Create box");
255         CString text(Message.ToCString());
256         myCResultDialog.SetText(text);
257 }
258
259 void 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
271         // Create a new box using the CNewCylDlg Dialog parameters as attributes
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));
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\
291 Handle(TDocStd_Document) D = GetOcafDoc(); \n\
292  \n\
293 //  Openning a new command (for undo/redo) \n\
294 D->NewCommand(); \n\
295  \n\
296 TOcaf_Commands TSC(D->Main()); \n\
297 // Look at the TOcaf_Commands::CreateCyl() function \n\
298 TDF_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\
301 Handle(TPrsStd_AISPresentation) prs; \n\
302 prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID()); \n\
303  \n\
304 //  Displaying the cylinder \n\
305 prs->Display(1); \n\
306  \n\
307 //  Commint the command (for undo/redo) \n\
308 D->CommitCommand(); \n\
309 \n");
310
311         myCResultDialog.SetTitle("Create cylinder");
312         CString text(Message.ToCString());
313         myCResultDialog.SetText(text);
314 }
315
316 void 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         {
332                 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Object cannot be modify.", L"Modification", MB_ICONEXCLAMATION);
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         Handle(TFunction_Logbook) log = TFunction_Logbook::Set(D->Main());
340
341         TCollection_AsciiString Message("\
342 //  Modification and recomputation of the selected object \n\
343  \n\
344 Handle(TDocStd_Document) D = GetOcafDoc(); \n\
345  \n\
346 //  Getting the TPrsStd_AISPresentation of the selected object \n\
347 Handle(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\
351 TDF_Label LabObject = ObjectPrs->Label(); \n\
352  \n\
353 //  Getting the TFunction_FunctionDriver ID attached to this label \n\
354 Handle(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
389                 // Modify the box
390                 TOcaf_Commands TSC(LabObject);
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);
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\
405 if(myDriverID==TOcafFunction_BoxDriver::GetID()){ \n\
406  \n\
407 //  Getting values of box attributes \n\
408 Handle(TDataStd_Real) curReal; \n\
409 LabObject.FindChild(1).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
410 w=curReal->Get(); \n\
411 LabObject.FindChild(2).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
412 l=curReal->Get(); \n\
413 LabObject.FindChild(3).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
414 h=curReal->Get(); \n\
415 LabObject.FindChild(4).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
416 x=curReal->Get(); \n\
417 LabObject.FindChild(5).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
418 y=curReal->Get(); \n\
419 LabObject.FindChild(6).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
420 z=curReal->Get(); \n\
421 Handle(TDataStd_Name) stdName; \n\
422 LabObject.FindAttribute(TDataStd_Name::GetID(),stdName); \n\
423  \n\
424 //  Openning a new command \n\
425 D->NewCommand(); \n\
426  \n\
427 TOcaf_Commands TSC(LabObject); \n\
428 // Look at the TOcaf_Commands::ModifyBox() function \n\
429 TSC.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\
432 Handle(TPrsStd_AISPresentation) prs; \n\
433 prs= TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID()); \n\
434  \n\
435 // Display the box \n\
436 prs->Display(1); \n\
437  \n\
438 // Commit the command \n\
439 D->CommitCommand(); \n\
440 } \n\
441 \n");
442
443                 myCResultDialog.SetTitle("Modify Box");
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
474                 // Modify the cylinder
475                 TOcaf_Commands TSC(LabObject);
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);
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\
490 if(myDriverID==TOcafFunction_CylDriver::GetID()){ \n\
491  \n\
492 //  Getting values of box cylinder \n\
493 Handle(TDataStd_Real) curReal; \n\
494 LabObject.FindChild(1).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
495 r=curReal->Get(); \n\
496 LabObject.FindChild(2).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
497 h=curReal->Get(); \n\
498 LabObject.FindChild(3).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
499 x=curReal->Get(); \n\
500 LabObject.FindChild(4).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
501 y=curReal->Get(); \n\
502 LabObject.FindChild(5).FindAttribute(TDataStd_Real::GetID(),curReal); \n\
503 z=curReal->Get(); \n\
504 Handle(TDataStd_Name) stdName; \n\
505 LabObject.FindAttribute(TDataStd_Name::GetID(),stdName); \n\
506  \n\
507 //  Openning a new command \n\
508 D->NewCommand(); \n\
509  \n\
510 TOcaf_Commands TSC(LabObject); \n\
511 // Look at the TOcaf_Commands::ModifyCyl() function \n\
512 TSC.ModifyCyl(m_x, m_y, m_z, m_r, m_h, Name); \n\
513  \n\
514 // Set the TPrsStd_AISPresentation of the cylinder \n\
515 Handle(TPrsStd_AISPresentation) prs; \n\
516 prs= TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID()); \n\
517  \n\
518 // Display the cylinder \n\
519 prs->Display(1); \n\
520  \n\
521 // Commit the command \n\
522 D->CommitCommand(); \n\
523 } \n\
524 \n");
525
526                 myCResultDialog.SetTitle("Modify cylinder");
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                 }
590
591                 // Modify the cylinder
592                 TOcaf_Commands ToolTSC(ToolLab);
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);
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(TFunction_Driver) myCutDriver;
604                 if (TFunction_DriverTable::Get()->FindDriver(myDriverID, myCutDriver))
605             myCutDriver->Init(LabObject);
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))
612                                 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Recompute failed", L"Modify cut", MB_ICONEXCLAMATION);
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\
630 if(myDriverID==TOcafFunction_CutDriver::GetID()){ \n\
631  \n\
632 //  Getting values of cut attributes (which are reference to the shapes)\n\
633 Handle(TDF_Reference) OriginalRef; \n\
634 LabObject.FindChild(1).FindAttribute(TDF_Reference::GetID(),OriginalRef); \n\
635 Handle(TDF_Reference) ToolRef; \n\
636 LabObject.FindChild(2).FindAttribute(TDF_Reference::GetID(),ToolRef); \n\
637  \n\
638 //  Getting the label of the tool shape (to modify it)\n\
639 TDF_Label ToolLab=ToolRef->Get(); \n\
640  \n\
641 TOcaf_Commands TSC(ToolLab); \n\
642 // Look at the TOcaf_Commands::ModifyBox() function \n\
643 TSC.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\
646 Handle(TFunction_Driver) myCutDriver; \n\
647 TFunction_DriverTable::Get()->FindDriver(myDriverID, myCutDriver); \n\
648  \n\
649 //  Recompute the cut if it must be (if an attribute was modified)\n\
650 if (myCutDriver->MustExecute(log)) { \n\
651         log.SetTouched(LabObject); \n\
652         myCutDriver->Execute(log) \n\
653 } \n\
654 Handle(TPrsStd_AISPresentation) prs; \n\
655  \n\
656 //  Setting the TPrsStd_AISPresentation of the cut object\n\
657 prs= TPrsStd_AISPresentation::Set(LabObject, TNaming_NamedShape::GetID()); \n\
658  \n\
659 //  Display the TPrsStd_AISPresentation of the cut object\n\
660 prs->Display(1); \n\
661  \n\
662 //  Commit the command\n\
663 D->CommitCommand(); \n\
664 } \n\
665 \n");
666
667                 myCResultDialog.SetTitle("Modify Cut");
668         }
669         else
670         {
671                 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"No associated function driver", L"Modify", MB_OK);
672         }
673
674         CString text(Message.ToCString());
675         myCResultDialog.SetText(text);
676 }
677
678 void 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
705 void 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\
757 Handle(TDocStd_Document) D = GetOcafDoc(); \n\
758 TDF_Label L = D->Main(); \n\
759  \n\
760 //  Openning a new command\n\
761 D->NewCommand(); \n\
762  \n\
763 TOcaf_Commands TSC(D->Main()); \n\
764  \n\
765 //  Create a box \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\
769  \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\
774  \n\
775 //  Cut the cylinder with the box \n\
776 L=TSC.Cut(L1, L2); \n\
777 Handle(TPrsStd_AISPresentation) prs; \n\
778  \n\
779 //  Setting the TPrsStd_AISPresentation of the cut object\n\
780 prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID()); \n\
781  \n\
782 //  Displaying the TPrsStd_AISPresentation of the cut object\n\
783 prs->Display(1); \n\
784  \n\
785 //  Commit the command\n\
786 D->CommitCommand(); \n\
787 \n");
788
789         myCResultDialog.SetTitle("Cut operation");
790         CString text(Message.ToCString());
791         myCResultDialog.SetText(text);
792 }
793
794
795 void 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
811 void 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");
855
856   myCResultDialog.SetTitle("Delete");
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
892 void COcafDoc::OnCloseDocument() 
893 {
894         Handle(TOcaf_Application) OcafApp = ((COcafApp*)AfxGetApp())->GetApp();
895         OcafApp->Close(myOcafDoc);
896         CDocument::OnCloseDocument();
897 }
898
899 void COcafDoc::OnFileSaveAs() 
900 {
901         const wchar_t* SPathName = PathName;
902         TCollection_ExtendedString TPathName ((Standard_ExtString )SPathName);
903
904         CString Filter;
905
906         if (TPathName.SearchFromEnd(".xml") > 0){
907                 Filter = "OCAFSample(XML) (*.xml)|*.xml|OCAFSample(Binary) (*.cbf)|*.cbf||";
908         } else {
909                 Filter = "OCAFSample(Binary) (*.cbf)|*.cbf|OCAFSample(XML) (*.xml)|*.xml||";
910         }
911         
912         CFileDialog dlg(FALSE,
913                         L"cbf",
914                         GetTitle(),
915                         OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
916                         Filter,
917                         NULL );
918         
919
920         Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp();
921         if (dlg.DoModal() != IDOK) return;
922
923         SetTitle(dlg.GetFileTitle());
924
925         CWaitCursor aWaitCursor;
926         CString CSPath = dlg.GetPathName();
927
928         cout << "Save As " << CSPath << endl;
929         PathName=CSPath;
930         const wchar_t* SPath = CSPath;
931         TCollection_ExtendedString TPath ((Standard_ExtString )SPath);
932
933             if (TPath.SearchFromEnd(".xml") > 0)
934                 {
935                   // The document must be saved in XML format
936                         myOcafDoc->ChangeStorageFormat("XmlOcaf");
937                 }
938                 else if (TPath.SearchFromEnd(".cbf") > 0)
939                 {
940                         // The document must be saved in binary format
941                         myOcafDoc->ChangeStorageFormat("BinOcaf");
942                 }
943
944                 try
945                 {
946                         // Saves the document in the current application
947                         m_App->SaveAs(myOcafDoc,TPath);
948                 }
949                 catch(...)
950                 {
951                         AfxMessageBox (L"Error! The file wasn't saved.");
952                 return;
953                 }
954 //      // save the document in the current application
955 //      m_App->SaveAs(myOcafDoc,TPath);
956
957         SetPathName(SPath);
958
959         TCollection_AsciiString Message = TCollection_AsciiString("\
960 //  Storing the document as \n\
961  \n\
962 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp(); \n\
963  \n\
964 //  Saving current OCAF document at TPath \n\
965 m_App->SaveAs(myOcafDoc,(TCollection_ExtendedString) TPath); \n\
966 \n");
967
968         myCResultDialog.SetTitle("Save a document");
969         CString text(Message.ToCString());
970         myCResultDialog.SetText(text);
971 }
972
973 void COcafDoc::OnFileSave() 
974 {
975         Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp();
976
977         
978         if (myOcafDoc.IsNull())
979         {
980           AfxMessageBox (L"Error during saving! Empty document.");
981           return;
982         }
983
984         if(PathName!="")
985         {
986           const wchar_t* SPath = PathName;
987           TCollection_ExtendedString TPath ((Standard_ExtString )SPath);
988
989             if (TPath.SearchFromEnd(".xml") > 0)
990                 {
991                   // The document must be saved in XML format
992                         myOcafDoc->ChangeStorageFormat("XmlOcaf");
993                 }
994                 else if (TPath.SearchFromEnd(".cbf") > 0)
995                 {
996                         // The document must be saved in binary format
997                         myOcafDoc->ChangeStorageFormat("BinOcaf");
998                 }
999
1000                 try
1001                 {
1002                         // Saves the document in the current application
1003                         m_App->SaveAs(myOcafDoc,TPath);
1004                 }
1005                 catch(...)
1006                 {
1007                         AfxMessageBox (L"Error! The file wasn't saved.");
1008                     return;
1009                 }
1010
1011         TCollection_AsciiString Message = TCollection_AsciiString("\
1012 //  Storing the document \n\
1013  \n\
1014 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp(); \n\
1015  \n\
1016 //  Saving current OCAF document at TPath \n\
1017 m_App->SaveAs(myOcafDoc,(TCollection_ExtendedString) TPath); \n\
1018 \n");
1019
1020                 myCResultDialog.SetTitle("Save a document");
1021                 CString text(Message.ToCString());
1022                 myCResultDialog.SetText(text);
1023                 return;
1024         }
1025
1026         CFileDialog dlg(FALSE,
1027                         L"cbf",
1028                         GetTitle(),
1029                         OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
1030                         L"OCAFSample(Binary) (*.cbf)|*.cbf|OCAFSample(XML) (*.xml)|*.xml||",
1031                         NULL );
1032
1033         if (dlg.DoModal() != IDOK) return;
1034
1035         SetTitle(dlg.GetFileTitle());
1036
1037         CWaitCursor aWaitCursor;
1038         CString CSPath = dlg.GetPathName();
1039
1040         const wchar_t* SPath = CSPath;
1041     TCollection_ExtendedString TPath ((Standard_ExtString )SPath);
1042
1043     // Choose storage format
1044     if (TPath.SearchFromEnd(".xml") > 0)
1045         {
1046           // The document must be saved in XML format
1047           myOcafDoc->ChangeStorageFormat("XmlOcaf");
1048         }
1049         else if (TPath.SearchFromEnd(".cbf") > 0)
1050         {
1051           // The document must be saved in binary format
1052           myOcafDoc->ChangeStorageFormat("BinOcaf");
1053         }
1054
1055    try
1056    {
1057           // Saves the document in the current application
1058           m_App->SaveAs(myOcafDoc,TPath);
1059    }
1060    catch(...)
1061    {
1062           AfxMessageBox (L"Error! The file wasn't saved.");
1063           return;
1064    }
1065
1066         SetPathName(SPath);
1067         PathName=CSPath;
1068
1069
1070         TCollection_AsciiString Message = TCollection_AsciiString("\
1071 //  Storing the document as \n\
1072  \n\
1073 Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp(); \n\
1074  \n\
1075 //  Saving current OCAF document at TPath \n\
1076 m_App->SaveAs(myOcafDoc,(TCollection_ExtendedString) TPath); \n\
1077 \n");
1078
1079         myCResultDialog.SetTitle("Save a document");
1080         CString text(Message.ToCString());
1081         myCResultDialog.SetText(text);
1082 }
1083
1084 BOOL COcafDoc::OnOpenDocument(LPCTSTR lpszPathName)
1085 {
1086   if (!CDocument::OnOpenDocument(lpszPathName))
1087   {
1088     return FALSE;
1089   }
1090
1091   Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp();
1092
1093   CWaitCursor aWaitCursor;
1094   PathName = lpszPathName;
1095
1096   const wchar_t* aPathName = lpszPathName;
1097   TCollection_ExtendedString anOccPathName ((Standard_ExtString)aPathName);
1098
1099   // Open the document in the current application
1100   //PCDM_ReaderStatus RS = m_App->Open(TPath,myOcafDoc);
1101   m_App->Open(anOccPathName, myOcafDoc);
1102   //CDF_RetrievableStatus RS = m_App->Open(TPath,myOcafDoc);
1103
1104   // Connect the document CAF (myDoc) with the AISContext (myAISContext)
1105   TPrsStd_AISViewer::New (myOcafDoc->Main(), myViewer);
1106   myOcafDoc->SetUndoLimit (10);
1107
1108   Handle(AIS_InteractiveContext) aContext;
1109   TPrsStd_AISViewer::Find (myOcafDoc->Main(), aContext);
1110   aContext->SetDisplayMode (AIS_Shaded);
1111   myAISContext = aContext;
1112
1113   // Display the presentations (which was not stored in the document)
1114   DisplayPrs();
1115
1116   TCollection_AsciiString Message = TCollection_AsciiString("\
1117 //  Retrieve a document \n\
1118  \n\
1119  Handle(TOcaf_Application) m_App= ((COcafApp*)AfxGetApp())->GetApp(); \n\
1120  \n\
1121 //  Openning the OCAF document from the TPath file\n\
1122 m_App->Open((TCollection_ExtendedString) TPath,myOcafDoc); \n\
1123  \n\
1124 //  Creation of a new TPrsStd_AISViewer connected to the current V3d_Viewer\n\
1125 TPrsStd_AISViewer::New(myOcafDoc->Main(),myViewer); \n\
1126  \n\
1127 //  Setting the number of memorized undos \n\
1128 myOcafDoc->SetUndoLimit(10); \n\
1129  \n\
1130 \n");
1131
1132   myCResultDialog.SetTitle ("Open a document");
1133   CString text (Message.ToCString());
1134   myCResultDialog.SetText (text);
1135
1136   return TRUE;
1137
1138 }
1139
1140
1141 void COcafDoc::EraseAll()
1142 {
1143         myOcafDoc->NewCommand();
1144
1145         TDF_Label LabSat = myOcafDoc->Main();
1146
1147         for (TDF_ChildIterator it(LabSat); it.More(); it.Next())
1148         {
1149                 TDF_Label L = it.Value();
1150                 Handle(TNaming_NamedShape) TNS;
1151                 if (!L.FindAttribute(TNaming_NamedShape::GetID(), TNS)) continue;
1152                 Handle(TDataStd_Integer) TDI;
1153
1154                 // To know if the object was displayed
1155                 if (L.FindAttribute(TDataStd_Integer::GetID(), TDI))
1156                         if(!TDI->Get())  continue;
1157
1158                 Handle(TPrsStd_AISPresentation) prs;
1159                 if (!L.FindAttribute(TPrsStd_AISPresentation::GetID(),prs))
1160                         prs = TPrsStd_AISPresentation::Set(L,TNaming_NamedShape::GetID());
1161                 prs->SetColor(Quantity_NOC_ORANGE);
1162                 prs->Erase(1);
1163     }
1164
1165         myAISContext->UpdateCurrentViewer();
1166
1167         myOcafDoc->CommitCommand();
1168 }
1169
1170 void  COcafDoc::Popup(const Standard_Integer  x,
1171                                                            const Standard_Integer  y ,
1172                                const Handle(V3d_View)& aView   ) 
1173 {
1174   Standard_Integer PopupMenuNumber=0;
1175  myAISContext->InitCurrent();
1176   if (myAISContext->MoreCurrent())
1177     PopupMenuNumber=1;
1178
1179   CMenu menu;
1180   VERIFY(menu.LoadMenu(IDR_Popup3D));
1181   CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber);
1182
1183   ASSERT(pPopup != NULL);
1184    if (PopupMenuNumber == 1) // more than 1 object.
1185   {
1186     bool OneOrMoreInShading = false;
1187         for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
1188     if (myAISContext->IsDisplayed(myAISContext->Current(),1)) OneOrMoreInShading=true;
1189         if(!OneOrMoreInShading)
1190         pPopup->EnableMenuItem(5, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
1191    }
1192
1193   POINT winCoord = { x , y };
1194   Handle(WNT_Window) aWNTWindow=
1195   Handle(WNT_Window)::DownCast(aView->Window());
1196   ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord);
1197   pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y , 
1198                          AfxGetMainWnd());
1199
1200
1201 }
1202
1203
1204 //void COcafDoc::OnDfbr() 
1205 //{
1206 //      // TODO: Add your command handler code here
1207 //      DebugBrowser::DFBrowser(myOcafDoc);
1208 //      
1209 //}