0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / XSDRAW / XSDRAW.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
15#include <DBRep.hxx>
42cf5bc1 16#include <Draw_Appli.hxx>
7fd59977 17#include <IFSelect_Functions.hxx>
18#include <IFSelect_SessionPilot.hxx>
42cf5bc1 19#include <Interface_InterfaceModel.hxx>
20#include <Interface_Macros.hxx>
21#include <Interface_Protocol.hxx>
22#include <Message.hxx>
23#include <Standard_Transient.hxx>
24#include <TCollection_AsciiString.hxx>
25#include <TColStd_HSequenceOfAsciiString.hxx>
7fd59977 26#include <TopoDS_Shape.hxx>
42cf5bc1 27#include <Transfer_FinderProcess.hxx>
28#include <Transfer_TransientProcess.hxx>
7fd59977 29#include <TransferBRep.hxx>
42cf5bc1 30#include <XSControl.hxx>
31#include <XSControl_Controller.hxx>
32#include <XSControl_FuncShape.hxx>
33#include <XSControl_Functions.hxx>
34#include <XSControl_TransferReader.hxx>
35#include <XSControl_TransferWriter.hxx>
36#include <XSControl_WorkSession.hxx>
37#include <XSDRAW.hxx>
38#include <XSDRAW_Vars.hxx>
7fd59977 39
7fd59977 40#include <stdio.h>
42cf5bc1 41//#include <XSDRAW_Shape.hxx>
7fd59977 42static int deja = 0, dejald = 0;
43//unused variable
44//static int okxset = 0;
45
997e128f 46static NCollection_DataMap<TCollection_AsciiString, Standard_Integer> theolds;
7fd59977 47static Handle(TColStd_HSequenceOfAsciiString) thenews;
48
49static Handle(IFSelect_SessionPilot) thepilot; // detient Session, Model
50
51static Standard_Integer XSTEPDRAWRUN (Draw_Interpretor& , Standard_Integer argc, const char** argv)
52{
53 TCollection_AsciiString mess;
54 for (Standard_Integer i = 0; i < argc; i ++) {
55 mess.AssignCat(argv[i]); mess.AssignCat(" ");
56 }
57
58 IFSelect_ReturnStatus stat = thepilot->Execute (mess.ToCString());
59 if (stat == IFSelect_RetError || stat == IFSelect_RetFail) return 1;
60 else return 0;
61}
62
63 void XSDRAW::ChangeCommand
64 (const Standard_CString oldname, const Standard_CString newname)
65{
7fd59977 66 Standard_Integer num = 0;
67 if (newname[0] != '\0') {
68 if (thenews.IsNull()) thenews = new TColStd_HSequenceOfAsciiString();
69 TCollection_AsciiString newstr(newname);
70 thenews->Append(newstr);
71 num = thenews->Length();
72 }
997e128f 73 theolds.Bind(oldname,num);
7fd59977 74}
75
76 void XSDRAW::RemoveCommand
77 (const Standard_CString oldname)
78{
79 ChangeCommand (oldname,"");
80}
81
82 Standard_Boolean XSDRAW::LoadSession ()
83{
84 if (deja) return Standard_False;
85 deja = 1;
86 thepilot = new IFSelect_SessionPilot("XSTEP-DRAW>");
87 Handle(XSControl_WorkSession) WS = new XSControl_WorkSession;
88 WS->SetVars (new XSDRAW_Vars);
89 thepilot->SetSession (WS);
90
91 IFSelect_Functions::Init();
92 XSControl_Functions::Init();
93 XSControl_FuncShape::Init();
94// XSDRAW_Shape::Init(); passe a present par theCommands
95 return Standard_True;
96}
97
98void XSDRAW::LoadDraw (Draw_Interpretor& theCommands)
99{
c48e2889 100 if (dejald)
101 {
102 return;
103 }
104 dejald = 1;
7da5f7b1 105// Pour tout faire d un coup : BRepTest & cie:
7fd59977 106 LoadSession();
107
108 //skl: we make remove commands "x" and "exit" in order to this commands are
109 // performed not in IFSelect_SessionPilot but in standard Tcl interpretor
110 XSDRAW::RemoveCommand("x");
111 XSDRAW::RemoveCommand("exit");
785a9540 112
7fd59977 113// if (!getenv("WBHOSTTOP")) XSDRAW::RemoveCommand("xsnew");
114 Handle(TColStd_HSequenceOfAsciiString) list =
115 IFSelect_Activator::Commands(0);
116 TCollection_AsciiString com;
117 Standard_Integer i, nb = list->Length();
118 for (i = 1; i <= nb; i ++) {
119 Handle(IFSelect_Activator) act;
120 Standard_Integer nact, num = -1;
121 char help[200];
122 com = list->Value(i);
997e128f 123 if (!theolds.IsEmpty())
124 theolds.Find(com, num);
7fd59977 125 if (num == 0) continue;
126 if (!IFSelect_Activator::Select(com.ToCString(),nact,act))
91322f44 127 Sprintf (help,"type : xhelp %s for help",com.ToCString());
7fd59977 128 else if (!act.IsNull()) strcpy(help,act->Help(nact));
129 if (num < 0) theCommands.Add (com.ToCString(),help,XSTEPDRAWRUN,act->Group());
130 else theCommands.Add (thenews->Value(num).ToCString(),help,XSTEPDRAWRUN,act->Group());
131 }
132}
133
134 Standard_Integer XSDRAW::Execute
135 (const Standard_CString command, const Standard_CString varname)
136{
137 char mess[100];
91322f44 138 Sprintf (mess,command,varname);
302f96fb 139 thepilot->Execute (mess);
7fd59977 140 return 1; // stat ?
141}
142
143 Handle(IFSelect_SessionPilot) XSDRAW::Pilot ()
144 { return thepilot; }
145
146 Handle(XSControl_WorkSession) XSDRAW::Session ()
147 { return XSControl::Session(thepilot); }
148
149 void XSDRAW::SetController (const Handle(XSControl_Controller)& control)
150{
151 if (thepilot.IsNull()) XSDRAW::LoadSession();
152 if (control.IsNull()) cout<<"XSTEP Controller not defined"<<endl;
153 else if (!Session().IsNull()) Session()->SetController (control);
154 else cout<<"XSTEP Session badly or not defined"<<endl;
155}
156
157
158 Handle(XSControl_Controller) XSDRAW::Controller ()
159 { return Session()->NormAdaptor(); }
160
161 Standard_Boolean XSDRAW::SetNorm
7f56eba8 162 (const Standard_CString norm)
7fd59977 163{
7f56eba8 164 return Session()->SelectNorm (norm);
7fd59977 165}
166
167 Handle(Interface_Protocol) XSDRAW::Protocol ()
168 { return thepilot->Session()->Protocol(); }
169
170 Handle(Interface_InterfaceModel) XSDRAW::Model ()
171 { return thepilot->Session()->Model(); }
172
173 void XSDRAW::SetModel
174 (const Handle(Interface_InterfaceModel)& model, const Standard_CString file)
175{
176 thepilot->Session()->SetModel(model);
177 if (file && file[0] != '\0') thepilot->Session()->SetLoadedFile(file);
178}
179
180 Handle(Interface_InterfaceModel) XSDRAW::NewModel ()
181 { return Session()->NewModel(); }
182
183 Handle(Standard_Transient) XSDRAW::Entity (const Standard_Integer num)
184 { return thepilot->Session()->StartingEntity(num); }
185
186 Standard_Integer XSDRAW::Number (const Handle(Standard_Transient)& ent)
187 { return thepilot->Session()->StartingNumber(ent); }
188
189 void XSDRAW::SetTransferProcess (const Handle(Standard_Transient)& ATP)
190{
191 DeclareAndCast(Transfer_FinderProcess,FP,ATP);
192 DeclareAndCast(Transfer_TransientProcess,TP,ATP);
193
194// Cas FinderProcess ==> TransferWriter
195 if (!FP.IsNull()) Session()->SetMapWriter(FP);
196
197// Cas TransientProcess ==> TransferReader
198 if (!TP.IsNull()) {
199 if (!TP->Model().IsNull() && TP->Model() != Session()->Model())
200 Session()->SetModel (TP->Model());
201 Session()->SetMapReader(TP);
202 }
203}
204
205 Handle(Transfer_TransientProcess) XSDRAW::TransientProcess ()
206 { return Session()->TransferReader()->TransientProcess(); }
207
208 Handle(Transfer_FinderProcess) XSDRAW::FinderProcess ()
209 { return Session()->TransferWriter()->FinderProcess(); }
210
211
212 void XSDRAW::InitTransferReader (const Standard_Integer mode)
213{
214// 0 nullify 1 clear
215// 2 init TR avec contenu TP (roots) 3 init TP avec contenu TR
216// 4 init avec model (debut scratch)
217 Session()->InitTransferReader(mode);
218}
219
220 Handle(XSControl_TransferReader) XSDRAW::TransferReader ()
221 { return Session()->TransferReader(); }
222
223
224// ############ AUXILIAIRES #############
225
226 Handle(Standard_Transient) XSDRAW::GetEntity (const Standard_CString name)
227 { return IFSelect_Functions::GiveEntity (Session(),name); }
228
229 Standard_Integer XSDRAW::GetEntityNumber (const Standard_CString name)
230 { return IFSelect_Functions::GiveEntityNumber (Session(),name); }
231
232
233 Handle(TColStd_HSequenceOfTransient) XSDRAW::GetList
234 (const Standard_CString first, const Standard_CString second)
235{
236 Handle(TColStd_HSequenceOfTransient) list;
237 if (!first || first[0] == '\0') {
238 char ligne[80]; ligne[0] = '\0'; char truc;
239// cin.clear(); cin.get (ligne,79,'\n');
60be1f9b 240 cin >> ligne; Standard_Size ln = strlen(ligne);
7fd59977 241 char *ff = &ligne[0], *ss = NULL;
242 cin.get(truc); if (truc != '\n') { cin>>&ligne[ln+1]; ss = &ligne[ln+1]; }
243 return XSDRAW::GetList (ff,ss);
244 }
245// return IFSelect_Functions::GiveList (Session(),first,second);
246 return IFSelect_Functions::GiveList (Session(),first,second);
247}
248
249
250 Standard_Boolean XSDRAW::FileAndVar
251 (const Standard_CString file, const Standard_CString var,
252 const Standard_CString def,
253 TCollection_AsciiString& resfile, TCollection_AsciiString& resvar)
254{ return XSControl_FuncShape::FileAndVar
255 (XSDRAW::Session(),file,var,def,resfile,resvar); }
256
257 Standard_Integer XSDRAW::MoreShapes
258 (Handle(TopTools_HSequenceOfShape)& list, const Standard_CString name)
259{ return XSControl_FuncShape::MoreShapes (XSDRAW::Session(),list,name); }
260
261
262// FONCTION POUR LE DEBUG
263
857ffd5e 264Standard_Integer XSDRAW_WHAT (const Handle(Standard_Transient)& ent)
7fd59977 265{
266 if (ent.IsNull()) { cout<<"(Null Handle)"<<endl; return 0; }
267 Handle(Interface_InterfaceModel) model = XSDRAW::Model();
268 if (model.IsNull()) { cout<<"(No model) Type:"<<ent->DynamicType()->Name()<<endl; return 0; }
269 cout<<" Num/Id :";
270 model->Print (ent, Message::DefaultMessenger(), 0);
271 cout<<" -- Recorded Type:"<<model->TypeName (ent)<<endl;
272 return model->Number(ent);
273}