Warnings on vc14 were eliminated
[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{
100 if (dejald) return; dejald = 1;
7da5f7b1 101// Pour tout faire d un coup : BRepTest & cie:
7fd59977 102 LoadSession();
103
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");
785a9540 108
7fd59977 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;
117 char help[200];
118 com = list->Value(i);
997e128f 119 if (!theolds.IsEmpty())
120 theolds.Find(com, num);
7fd59977 121 if (num == 0) continue;
122 if (!IFSelect_Activator::Select(com.ToCString(),nact,act))
91322f44 123 Sprintf (help,"type : xhelp %s for help",com.ToCString());
7fd59977 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());
127 }
128}
129
130 Standard_Integer XSDRAW::Execute
131 (const Standard_CString command, const Standard_CString varname)
132{
133 char mess[100];
91322f44 134 Sprintf (mess,command,varname);
302f96fb 135 thepilot->Execute (mess);
7fd59977 136 return 1; // stat ?
137}
138
139 Handle(IFSelect_SessionPilot) XSDRAW::Pilot ()
140 { return thepilot; }
141
142 Handle(XSControl_WorkSession) XSDRAW::Session ()
143 { return XSControl::Session(thepilot); }
144
145 void XSDRAW::SetController (const Handle(XSControl_Controller)& control)
146{
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;
151}
152
153
154 Handle(XSControl_Controller) XSDRAW::Controller ()
155 { return Session()->NormAdaptor(); }
156
157 Standard_Boolean XSDRAW::SetNorm
7f56eba8 158 (const Standard_CString norm)
7fd59977 159{
7f56eba8 160 return Session()->SelectNorm (norm);
7fd59977 161}
162
163 Handle(Interface_Protocol) XSDRAW::Protocol ()
164 { return thepilot->Session()->Protocol(); }
165
166 Handle(Interface_InterfaceModel) XSDRAW::Model ()
167 { return thepilot->Session()->Model(); }
168
169 void XSDRAW::SetModel
170 (const Handle(Interface_InterfaceModel)& model, const Standard_CString file)
171{
172 thepilot->Session()->SetModel(model);
173 if (file && file[0] != '\0') thepilot->Session()->SetLoadedFile(file);
174}
175
176 Handle(Interface_InterfaceModel) XSDRAW::NewModel ()
177 { return Session()->NewModel(); }
178
179 Handle(Standard_Transient) XSDRAW::Entity (const Standard_Integer num)
180 { return thepilot->Session()->StartingEntity(num); }
181
182 Standard_Integer XSDRAW::Number (const Handle(Standard_Transient)& ent)
183 { return thepilot->Session()->StartingNumber(ent); }
184
185 void XSDRAW::SetTransferProcess (const Handle(Standard_Transient)& ATP)
186{
187 DeclareAndCast(Transfer_FinderProcess,FP,ATP);
188 DeclareAndCast(Transfer_TransientProcess,TP,ATP);
189
190// Cas FinderProcess ==> TransferWriter
191 if (!FP.IsNull()) Session()->SetMapWriter(FP);
192
193// Cas TransientProcess ==> TransferReader
194 if (!TP.IsNull()) {
195 if (!TP->Model().IsNull() && TP->Model() != Session()->Model())
196 Session()->SetModel (TP->Model());
197 Session()->SetMapReader(TP);
198 }
199}
200
201 Handle(Transfer_TransientProcess) XSDRAW::TransientProcess ()
202 { return Session()->TransferReader()->TransientProcess(); }
203
204 Handle(Transfer_FinderProcess) XSDRAW::FinderProcess ()
205 { return Session()->TransferWriter()->FinderProcess(); }
206
207
208 void XSDRAW::InitTransferReader (const Standard_Integer mode)
209{
210// 0 nullify 1 clear
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);
214}
215
216 Handle(XSControl_TransferReader) XSDRAW::TransferReader ()
217 { return Session()->TransferReader(); }
218
219
220// ############ AUXILIAIRES #############
221
222 Handle(Standard_Transient) XSDRAW::GetEntity (const Standard_CString name)
223 { return IFSelect_Functions::GiveEntity (Session(),name); }
224
225 Standard_Integer XSDRAW::GetEntityNumber (const Standard_CString name)
226 { return IFSelect_Functions::GiveEntityNumber (Session(),name); }
227
228
229 Handle(TColStd_HSequenceOfTransient) XSDRAW::GetList
230 (const Standard_CString first, const Standard_CString second)
231{
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');
60be1f9b 236 cin >> ligne; Standard_Size ln = strlen(ligne);
7fd59977 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);
240 }
241// return IFSelect_Functions::GiveList (Session(),first,second);
242 return IFSelect_Functions::GiveList (Session(),first,second);
243}
244
245
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); }
252
253 Standard_Integer XSDRAW::MoreShapes
254 (Handle(TopTools_HSequenceOfShape)& list, const Standard_CString name)
255{ return XSControl_FuncShape::MoreShapes (XSDRAW::Session(),list,name); }
256
257
258// FONCTION POUR LE DEBUG
259
857ffd5e 260Standard_Integer XSDRAW_WHAT (const Handle(Standard_Transient)& ent)
7fd59977 261{
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; }
265 cout<<" Num/Id :";
266 model->Print (ent, Message::DefaultMessenger(), 0);
267 cout<<" -- Recorded Type:"<<model->TypeName (ent)<<endl;
268 return model->Number(ent);
269}