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)
100 if (dejald) return; dejald = 1;
101 // Pour tout faire d un coup : BRepTest & cie:
104 //skl: we make remove commands "x" and "exit" in order to this commands are
105 // performed not in IFSelect_SessionPilot but in standard Tcl interpretor
106 XSDRAW::RemoveCommand("x");
107 XSDRAW::RemoveCommand("exit");
109 // if (!getenv("WBHOSTTOP")) XSDRAW::RemoveCommand("xsnew");
110 Handle(TColStd_HSequenceOfAsciiString) list =
111 IFSelect_Activator::Commands(0);
112 TCollection_AsciiString com;
113 Standard_Integer i, nb = list->Length();
114 for (i = 1; i <= nb; i ++) {
115 Handle(IFSelect_Activator) act;
116 Standard_Integer nact, num = -1;
118 com = list->Value(i);
119 if (!theolds.IsEmpty())
120 theolds.Find(com, num);
121 if (num == 0) continue;
122 if (!IFSelect_Activator::Select(com.ToCString(),nact,act))
123 Sprintf (help,"type : xhelp %s for help",com.ToCString());
124 else if (!act.IsNull()) strcpy(help,act->Help(nact));
125 if (num < 0) theCommands.Add (com.ToCString(),help,XSTEPDRAWRUN,act->Group());
126 else theCommands.Add (thenews->Value(num).ToCString(),help,XSTEPDRAWRUN,act->Group());
130 Standard_Integer XSDRAW::Execute
131 (const Standard_CString command, const Standard_CString varname)
134 Sprintf (mess,command,varname);
135 thepilot->Execute (mess);
139 Handle(IFSelect_SessionPilot) XSDRAW::Pilot ()
142 Handle(XSControl_WorkSession) XSDRAW::Session ()
143 { return XSControl::Session(thepilot); }
145 void XSDRAW::SetController (const Handle(XSControl_Controller)& control)
147 if (thepilot.IsNull()) XSDRAW::LoadSession();
148 if (control.IsNull()) cout<<"XSTEP Controller not defined"<<endl;
149 else if (!Session().IsNull()) Session()->SetController (control);
150 else cout<<"XSTEP Session badly or not defined"<<endl;
154 Handle(XSControl_Controller) XSDRAW::Controller ()
155 { return Session()->NormAdaptor(); }
157 Standard_Boolean XSDRAW::SetNorm
158 (const Standard_CString norm)
160 return Session()->SelectNorm (norm);
163 Handle(Interface_Protocol) XSDRAW::Protocol ()
164 { return thepilot->Session()->Protocol(); }
166 Handle(Interface_InterfaceModel) XSDRAW::Model ()
167 { return thepilot->Session()->Model(); }
169 void XSDRAW::SetModel
170 (const Handle(Interface_InterfaceModel)& model, const Standard_CString file)
172 thepilot->Session()->SetModel(model);
173 if (file && file[0] != '\0') thepilot->Session()->SetLoadedFile(file);
176 Handle(Interface_InterfaceModel) XSDRAW::NewModel ()
177 { return Session()->NewModel(); }
179 Handle(Standard_Transient) XSDRAW::Entity (const Standard_Integer num)
180 { return thepilot->Session()->StartingEntity(num); }
182 Standard_Integer XSDRAW::Number (const Handle(Standard_Transient)& ent)
183 { return thepilot->Session()->StartingNumber(ent); }
185 void XSDRAW::SetTransferProcess (const Handle(Standard_Transient)& ATP)
187 DeclareAndCast(Transfer_FinderProcess,FP,ATP);
188 DeclareAndCast(Transfer_TransientProcess,TP,ATP);
190 // Cas FinderProcess ==> TransferWriter
191 if (!FP.IsNull()) Session()->SetMapWriter(FP);
193 // Cas TransientProcess ==> TransferReader
195 if (!TP->Model().IsNull() && TP->Model() != Session()->Model())
196 Session()->SetModel (TP->Model());
197 Session()->SetMapReader(TP);
201 Handle(Transfer_TransientProcess) XSDRAW::TransientProcess ()
202 { return Session()->TransferReader()->TransientProcess(); }
204 Handle(Transfer_FinderProcess) XSDRAW::FinderProcess ()
205 { return Session()->TransferWriter()->FinderProcess(); }
208 void XSDRAW::InitTransferReader (const Standard_Integer mode)
211 // 2 init TR avec contenu TP (roots) 3 init TP avec contenu TR
212 // 4 init avec model (debut scratch)
213 Session()->InitTransferReader(mode);
216 Handle(XSControl_TransferReader) XSDRAW::TransferReader ()
217 { return Session()->TransferReader(); }
220 // ############ AUXILIAIRES #############
222 Handle(Standard_Transient) XSDRAW::GetEntity (const Standard_CString name)
223 { return IFSelect_Functions::GiveEntity (Session(),name); }
225 Standard_Integer XSDRAW::GetEntityNumber (const Standard_CString name)
226 { return IFSelect_Functions::GiveEntityNumber (Session(),name); }
229 Handle(TColStd_HSequenceOfTransient) XSDRAW::GetList
230 (const Standard_CString first, const Standard_CString second)
232 Handle(TColStd_HSequenceOfTransient) list;
233 if (!first || first[0] == '\0') {
234 char ligne[80]; ligne[0] = '\0'; char truc;
235 // cin.clear(); cin.get (ligne,79,'\n');
236 cin >> ligne; Standard_Size ln = strlen(ligne);
237 char *ff = &ligne[0], *ss = NULL;
238 cin.get(truc); if (truc != '\n') { cin>>&ligne[ln+1]; ss = &ligne[ln+1]; }
239 return XSDRAW::GetList (ff,ss);
241 // return IFSelect_Functions::GiveList (Session(),first,second);
242 return IFSelect_Functions::GiveList (Session(),first,second);
246 Standard_Boolean XSDRAW::FileAndVar
247 (const Standard_CString file, const Standard_CString var,
248 const Standard_CString def,
249 TCollection_AsciiString& resfile, TCollection_AsciiString& resvar)
250 { return XSControl_FuncShape::FileAndVar
251 (XSDRAW::Session(),file,var,def,resfile,resvar); }
253 Standard_Integer XSDRAW::MoreShapes
254 (Handle(TopTools_HSequenceOfShape)& list, const Standard_CString name)
255 { return XSControl_FuncShape::MoreShapes (XSDRAW::Session(),list,name); }
258 // FONCTION POUR LE DEBUG
260 Standard_Integer XSDRAW_WHAT (const Handle(Standard_Transient)& ent)
262 if (ent.IsNull()) { cout<<"(Null Handle)"<<endl; return 0; }
263 Handle(Interface_InterfaceModel) model = XSDRAW::Model();
264 if (model.IsNull()) { cout<<"(No model) Type:"<<ent->DynamicType()->Name()<<endl; return 0; }
266 model->Print (ent, Message::DefaultMessenger(), 0);
267 cout<<" -- Recorded Type:"<<model->TypeName (ent)<<endl;
268 return model->Number(ent);