f1133ea4a51f43eb86db5d7b4273b4f98c2c7aab
[occt.git] / src / DPrsStd / DPrsStd_AISViewerCommands.cxx
1 // Created on: 1998-10-27
2 // Created by: Denis PASCAL
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <DPrsStd.hxx>
18
19 #include <DPrsStd.hxx>
20 #include <Draw.hxx>
21 #include <Draw_Appli.hxx>
22 #include <Draw_Interpretor.hxx>
23 #include <Draw_ColorKind.hxx>
24 #include <TCollection_AsciiString.hxx>
25 #include <TDocStd_Document.hxx>
26 #include <TDF_Label.hxx>
27 #include <TDF_Data.hxx> 
28 #include <TDF_Tool.hxx> 
29 #include <TDF_ChildIterator.hxx>
30 #include <DDF.hxx>
31 #include <DDocStd.hxx>
32 #include <TDocStd_Document.hxx> 
33 #include <ViewerTest.hxx>
34
35 #include <V3d_View.hxx>
36
37 // for AIS
38
39 #include <TPrsStd_AISPresentation.hxx>
40 #include <TPrsStd_AISViewer.hxx>
41 #include <ViewerTest.hxx>
42 #include <AIS_InteractiveContext.hxx> 
43 #include <ViewerTest.hxx>
44 #include <ViewerTest_Tool.hxx>
45 #include <V3d_View.hxx>
46
47
48
49 extern int ViewerMainLoop (Standard_Integer, const char**);
50
51 //=======================================================================
52 //function : DPrsStd_AISInitViewer
53 //purpose  : AISInitViewer (DOC)
54 //=======================================================================
55 extern void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)&);
56
57 static Standard_Integer DPrsStd_AISInitViewer (Draw_Interpretor& di,
58                                              Standard_Integer nb, 
59                                              const char** arg) 
60 {   
61   if (nb == 2) {     
62     Handle(TDocStd_Document) D;
63     if (!DDocStd::GetDocument(arg[1],D)) return 1; 
64     TDF_Label acces = D->GetData()->Root();   
65     Handle(TPrsStd_AISViewer) viewer;
66     if (!TPrsStd_AISViewer::Find (acces,viewer)) {
67       TCollection_AsciiString title;  
68       title.Prepend(arg[1]);   
69       title.Prepend("_"); 
70       title.Prepend("Document");  
71       Handle(V3d_Viewer) vw = ViewerTest_Tool::MakeViewer (title.ToCString());
72       viewer = TPrsStd_AISViewer::New (acces,vw);
73     } 
74     ViewerTest_Tool::InitViewerTest (viewer->GetInteractiveContext());
75     DDF::ReturnLabel(di,viewer->Label());
76     return 0;
77   }
78   di << "DPrsStd_AISInitViewer : Error" << "\n";
79   return 1;
80 }
81
82
83 //=======================================================================
84 //function : TPrsStd_AISRepaint
85 //purpose  : 
86 //=======================================================================
87
88 static Standard_Integer DPrsStd_AISRepaint (Draw_Interpretor& di,
89                                             Standard_Integer nb, 
90                                             const char** arg) 
91 {   
92   if (nb == 2) {     
93     Handle(TDocStd_Document) D;
94     if (!DDocStd::GetDocument(arg[1],D)) return 1; 
95     TDF_Label acces = D->GetData()->Root(); 
96     TPrsStd_AISViewer::Update(acces);
97     return 0;
98   }
99   di << "DPrsStd_AISRepaint : Error" << "\n";
100   return 1; 
101 }
102
103 //=======================================================================
104 //function : AISViewerCommands
105 //purpose  :
106 //=======================================================================
107
108
109 void DPrsStd::AISViewerCommands (Draw_Interpretor& theCommands)
110 {  
111
112   static Standard_Boolean done = Standard_False;
113   if (done) return;
114   done = Standard_True;
115   const char* g = "DPrsStd : standard presentation commands" ;  
116  
117   // standard commands working on AISViewer
118   
119   theCommands.Add ("AISInitViewer", 
120                    "AISInitViewer (DOC)",
121                    __FILE__, DPrsStd_AISInitViewer, g);    
122
123   theCommands.Add ("AISRepaint", 
124                    "update the AIS viewer",
125                    __FILE__, DPrsStd_AISRepaint, g);      
126 }