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