1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
16 #include <Draw_Appli.hxx>
17 #include <IFSelect_Functions.hxx>
18 #include <IFSelect_SessionPilot.hxx>
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>
26 #include <TopoDS_Shape.hxx>
27 #include <Transfer_FinderProcess.hxx>
28 #include <Transfer_TransientProcess.hxx>
29 #include <TransferBRep.hxx>
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>
38 #include <XSDRAW_Vars.hxx>
41 //#include <XSDRAW_Shape.hxx>
42 static int deja = 0, dejald = 0;
44 //static int okxset = 0;
46 static NCollection_DataMap<TCollection_AsciiString, Standard_Integer> theolds;
47 static Handle(TColStd_HSequenceOfAsciiString) thenews;
49 static Handle(IFSelect_SessionPilot) thepilot; // detient Session, Model
51 static Standard_Integer XSTEPDRAWRUN (Draw_Interpretor& , Standard_Integer argc, const char** argv)
53 TCollection_AsciiString mess;
54 for (Standard_Integer i = 0; i < argc; i ++) {
55 mess.AssignCat(argv[i]); mess.AssignCat(" ");
58 IFSelect_ReturnStatus stat = thepilot->Execute (mess.ToCString());
59 if (stat == IFSelect_RetError || stat == IFSelect_RetFail) return 1;
63 void XSDRAW::ChangeCommand
64 (const Standard_CString oldname, const Standard_CString newname)
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();
73 theolds.Bind(oldname,num);
76 void XSDRAW::RemoveCommand
77 (const Standard_CString oldname)
79 ChangeCommand (oldname,"");
82 Standard_Boolean XSDRAW::LoadSession ()
84 if (deja) return Standard_False;
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);
91 IFSelect_Functions::Init();
92 XSControl_Functions::Init();
93 XSControl_FuncShape::Init();
94 // XSDRAW_Shape::Init(); passe a present par theCommands
98 void XSDRAW::LoadDraw (Draw_Interpretor& theCommands)
105 // Pour tout faire d un coup : BRepTest & cie:
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");
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;
122 com = list->Value(i);
123 if (!theolds.IsEmpty())
124 theolds.Find(com, num);
125 if (num == 0) continue;
126 if (!IFSelect_Activator::Select(com.ToCString(),nact,act))
127 Sprintf (help,"type : xhelp %s for help",com.ToCString());
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());
134 Standard_Integer XSDRAW::Execute
135 (const Standard_CString command, const Standard_CString varname)
138 Sprintf (mess,command,varname);
139 thepilot->Execute (mess);
143 Handle(IFSelect_SessionPilot) XSDRAW::Pilot ()
146 Handle(XSControl_WorkSession) XSDRAW::Session ()
147 { return XSControl::Session(thepilot); }
149 void XSDRAW::SetController (const Handle(XSControl_Controller)& control)
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;
158 Handle(XSControl_Controller) XSDRAW::Controller ()
159 { return Session()->NormAdaptor(); }
161 Standard_Boolean XSDRAW::SetNorm
162 (const Standard_CString norm)
164 return Session()->SelectNorm (norm);
167 Handle(Interface_Protocol) XSDRAW::Protocol ()
168 { return thepilot->Session()->Protocol(); }
170 Handle(Interface_InterfaceModel) XSDRAW::Model ()
171 { return thepilot->Session()->Model(); }
173 void XSDRAW::SetModel
174 (const Handle(Interface_InterfaceModel)& model, const Standard_CString file)
176 thepilot->Session()->SetModel(model);
177 if (file && file[0] != '\0') thepilot->Session()->SetLoadedFile(file);
180 Handle(Interface_InterfaceModel) XSDRAW::NewModel ()
181 { return Session()->NewModel(); }
183 Handle(Standard_Transient) XSDRAW::Entity (const Standard_Integer num)
184 { return thepilot->Session()->StartingEntity(num); }
186 Standard_Integer XSDRAW::Number (const Handle(Standard_Transient)& ent)
187 { return thepilot->Session()->StartingNumber(ent); }
189 void XSDRAW::SetTransferProcess (const Handle(Standard_Transient)& ATP)
191 DeclareAndCast(Transfer_FinderProcess,FP,ATP);
192 DeclareAndCast(Transfer_TransientProcess,TP,ATP);
194 // Cas FinderProcess ==> TransferWriter
195 if (!FP.IsNull()) Session()->SetMapWriter(FP);
197 // Cas TransientProcess ==> TransferReader
199 if (!TP->Model().IsNull() && TP->Model() != Session()->Model())
200 Session()->SetModel (TP->Model());
201 Session()->SetMapReader(TP);
205 Handle(Transfer_TransientProcess) XSDRAW::TransientProcess ()
206 { return Session()->TransferReader()->TransientProcess(); }
208 Handle(Transfer_FinderProcess) XSDRAW::FinderProcess ()
209 { return Session()->TransferWriter()->FinderProcess(); }
212 void XSDRAW::InitTransferReader (const Standard_Integer mode)
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);
220 Handle(XSControl_TransferReader) XSDRAW::TransferReader ()
221 { return Session()->TransferReader(); }
224 // ############ AUXILIAIRES #############
226 Handle(Standard_Transient) XSDRAW::GetEntity (const Standard_CString name)
227 { return IFSelect_Functions::GiveEntity (Session(),name); }
229 Standard_Integer XSDRAW::GetEntityNumber (const Standard_CString name)
230 { return IFSelect_Functions::GiveEntityNumber (Session(),name); }
233 Handle(TColStd_HSequenceOfTransient) XSDRAW::GetList
234 (const Standard_CString first, const Standard_CString second)
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');
240 cin >> ligne; Standard_Size ln = strlen(ligne);
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);
245 // return IFSelect_Functions::GiveList (Session(),first,second);
246 return IFSelect_Functions::GiveList (Session(),first,second);
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); }
257 Standard_Integer XSDRAW::MoreShapes
258 (Handle(TopTools_HSequenceOfShape)& list, const Standard_CString name)
259 { return XSControl_FuncShape::MoreShapes (XSDRAW::Session(),list,name); }
262 // FONCTION POUR LE DEBUG
264 Standard_Integer XSDRAW_WHAT (const Handle(Standard_Transient)& ent)
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; }
270 model->Print (ent, Message::DefaultMessenger(), 0);
271 cout<<" -- Recorded Type:"<<model->TypeName (ent)<<endl;
272 return model->Number(ent);