e670d76c12af410ce755e5aa8cdec2dbc851f297
[occt.git] / src / IGESData / IGESData.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 // Integration to ensure SCCS base integrity
19 //#58 rln 28.12.98 changing default values for Global Section
20 //pdn 11.01.99 including <stdio.h> for compilation on NT
21 //gka 19.01.99 changing date parameters and  number of IGES version, adding parameter(ApllicationProtocol)
22 //#65 rln 12.02.99 S4151 (explicitly force YYMMDD.HHMMSS before Y2000 and YYYYMMDD.HHMMSS after Y2000)
23
24 #include <stdio.h>
25 #include <IGESData.ixx>
26 #include <IGESData_Protocol.hxx>
27 #include <IGESData_DefaultGeneral.hxx>
28 #include <IGESData_DefaultSpecific.hxx>
29
30 #include <TCollection_HAsciiString.hxx>
31 #include <IGESData_GlobalSection.hxx>
32 #include <IGESData_IGESModel.hxx>
33 #include <Interface_InterfaceModel.hxx>
34
35 #include <Interface_Static.hxx>
36 #include <Message_MsgFile.hxx>
37 #include <Standard_Integer.hxx>
38 #include <Standard_Real.hxx>
39 #include <OSD_Process.hxx>
40
41 #include <Interface_Version.hxx>
42 #include <Quantity_Date.hxx>
43
44
45 static Handle(IGESData_Protocol) proto;
46
47 static Handle(IGESData_DefaultGeneral)    stmod;
48 static Handle(IGESData_DefaultSpecific)   speci;
49
50
51     void  IGESData::Init ()
52 {
53   if (proto.IsNull()) proto = new IGESData_Protocol;
54   if (stmod.IsNull()) stmod = new IGESData_DefaultGeneral;
55   if (speci.IsNull()) speci = new IGESData_DefaultSpecific;
56 //  et modele template "iges"
57   if (Interface_InterfaceModel::HasTemplate("iges")) return;
58
59   OSD_Process process;
60
61   // Static Parameters - see also Static Standards
62   // -----------------
63   Interface_Static::Standards();
64
65   Interface_Static::Init ("XSTEP","read.iges.bspline.approxd1.mode",'e',"");
66   Interface_Static::Init ("XSTEP","read.iges.bspline.approxd1.mode",'&',"ematch 0");
67   Interface_Static::Init ("XSTEP","read.iges.bspline.approxd1.mode",'&',"eval Off");
68   Interface_Static::Init ("XSTEP","read.iges.bspline.approxd1.mode",'&',"eval On");
69   Interface_Static::SetIVal ("read.iges.bspline.approxd1.mode",0);
70
71   Interface_Static::Init ("XSTEP","read.iges.bspline.continuity",'i',"1");
72   Interface_Static::Init ("XSTEP","read.iges.bspline.continuity",'&',"imin 0");
73   Interface_Static::Init ("XSTEP","read.iges.bspline.continuity",'&',"imax 2");
74
75   //#58 rln Interface_Static::Init ("XSTEP","write.iges.header.product" ,'t',"");
76   Interface_Static::Init ("XSTEP","write.iges.header.receiver",'t',"");//58 rln Unknown
77   Interface_Static::Init ("XSTEP","write.iges.header.author"  ,'t',process.UserName().ToCString());
78   Interface_Static::Init ("XSTEP","write.iges.header.company" ,'t',"");//58 rln Matra Datavision
79
80   Interface_Static::Init ("XSTEP","write.iges.unit",'e',"");
81   Interface_Static::Init ("XSTEP","write.iges.unit",'&',"enum 1");
82   Interface_Static::Init ("XSTEP","write.iges.unit",'&',"eval INCH");  // 1
83   Interface_Static::Init ("XSTEP","write.iges.unit",'&',"eval MM");    // 2
84   Interface_Static::Init ("XSTEP","write.iges.unit",'&',"eval ??");    // 3
85   Interface_Static::Init ("XSTEP","write.iges.unit",'&',"eval FT");    // 4
86   Interface_Static::Init ("XSTEP","write.iges.unit",'&',"eval MI");    // 5
87   Interface_Static::Init ("XSTEP","write.iges.unit",'&',"eval M");     // 6
88   Interface_Static::Init ("XSTEP","write.iges.unit",'&',"eval KM");    // 7
89   Interface_Static::Init ("XSTEP","write.iges.unit",'&',"eval MIL");   // 8
90   Interface_Static::Init ("XSTEP","write.iges.unit",'&',"eval UM");    // 9
91   Interface_Static::Init ("XSTEP","write.iges.unit",'&',"eval CM");    //10
92   Interface_Static::Init ("XSTEP","write.iges.unit",'&',"eval UIN");   //11
93   Interface_Static::SetCVal ("write.iges.unit","MM");
94
95   Interface_Static::Init ("XSTEP","write.iges.brep.mode",'e',"");
96   Interface_Static::Init ("XSTEP","write.iges.brep.mode",'&',"ematch 0");
97   Interface_Static::Init ("XSTEP","write.iges.brep.mode",'&',"eval Faces");
98   Interface_Static::Init ("XSTEP","write.iges.brep.mode",'&',"eval BRep");
99   Interface_Static::SetIVal ("write.iges.brep.mode",0);
100
101   //S4181 pdn 23.04.99: adding new parameter handling writing of elementary surfaces
102   Interface_Static::Init ("XSTEP","write.convertsurface.mode",'e',"");
103   Interface_Static::Init ("XSTEP","write.convertsurface.mode",'&',"ematch 0");
104   Interface_Static::Init ("XSTEP","write.convertsurface.mode",'&',"eval Off");
105   Interface_Static::Init ("XSTEP","write.convertsurface.mode",'&',"eval On");
106   Interface_Static::SetIVal ("write.convertsurface.mode",0);
107
108   // abv 15.11.00: ShapeProcessing
109   Interface_Static::Init ("XSTEP","write.iges.resource.name",'t',"IGES");
110   Interface_Static::Init ("XSTEP","read.iges.resource.name",'t',"IGES");
111   Interface_Static::Init ("XSTEP","write.iges.sequence",'t',"ToIGES");
112   Interface_Static::Init ("XSTEP","read.iges.sequence",'t',"FromIGES");
113   
114   // sln 11.06.2002 OCC448 : Initialize "read.onlyvisible" parameter  to control transfering 
115   // invisiable sub entities which logicaly depend on the grouping entities
116   Interface_Static::Init ("XSTEP","read.iges.onlyvisible",'e',"");
117   Interface_Static::Init ("XSTEP","read.iges.onlyvisible",'&',"ematch 0");
118   Interface_Static::Init ("XSTEP","read.iges.onlyvisible",'&',"eval Off");
119   Interface_Static::Init ("XSTEP","read.iges.onlyvisible",'&',"eval On");
120   Interface_Static::SetIVal ("read.iges.onlyvisible",0);
121
122   //gka added parameter for reading failed entities. 19.07
123   Interface_Static::Init ("XSTEP","read.iges.faulty.entities",'e',"");
124   Interface_Static::Init ("XSTEP","read.iges.faulty.entities",'&',"ematch 0");
125   Interface_Static::Init ("XSTEP","read.iges.faulty.entities",'&',"eval Off");
126   Interface_Static::Init ("XSTEP","read.iges.faulty.entities",'&',"eval On");
127   Interface_Static::SetIVal ("read.iges.faulty.entities",0);
128   // Message File for IGES
129   // -----------------
130
131   Message_MsgFile::LoadFromEnv ("CSF_XSMessage","IGES");
132
133   // Creating the Global Section
134   //----------------------------
135
136   IGESData_GlobalSection GS;
137   //#58 rln 28.12.98 changing default values for Global Section
138   char procver[80];
139   sprintf (procver, XSTEP_PROCESSOR_VERSION, "IGES");
140   Handle(TCollection_HAsciiString) gsys = new TCollection_HAsciiString (procver);
141   Interface_Static::Init ("XSTEP","write.iges.header.product" ,'t',procver);
142   
143 /*  Handle(TCollection_HAsciiString) gsys = new TCollection_HAsciiString
144     (XSTEP_VERSION);
145   gsys->AssignCat(" on ");
146   gsys->AssignCat
147 #ifdef HPUX
148     ("HP-UX");
149   cout<<"--  OSD_Path::SystemVersion, does not work well on HP-UX"<<endl;
150 #endif
151 #ifndef HPUX
152     (host.SystemVersion().ToCString());
153 #endif
154
155 //  SendName : nom significatif de la piece transmise par exemple
156 //  SystemId : c est MDTV etc
157 //  InterfaceVersion : la version en cours de XSTEP; incluant la plateforme
158
159   char nomsys[100]; int istat; long lstat;
160   struct utsname infosy;
161   istat = uname (&infosy);
162   lstat = sysinfo (SI_HW_PROVIDER,nomsys,99);
163   Handle(TCollection_HAsciiString) gsys = new TCollection_HAsciiString(nomsys);
164   gsys->AssignCat(" ");
165   lstat = sysinfo (SI_ARCHITECTURE,nomsys,99);
166   gsys->AssignCat(nomsys);
167   gsys->AssignCat("/");
168   gsys->AssignCat(infosy.sysname);
169   gsys->AssignCat(" ");
170   gsys->AssignCat(infosy.release);
171 */
172   Standard_Integer year;                                //gka 19.01.99
173   OSD_Process system;
174   Quantity_Date ladate = system.SystemDate(); 
175   year = ladate.Year();
176   Handle(TCollection_HAsciiString) datestr;
177   if( year < 2000 )
178     //#65 rln 12.02.99 S4151 (explicitly force YYMMDD.HHMMSS before Y2000)
179     datestr = GS.NewDateString(0,0,0,0,0,0,0);
180   else 
181     //#65 rln 12.02.99 S4151 (explicitly force YYYYMMDD.HHMMSS after Y2000)
182     datestr = GS.NewDateString(0,0,0,0,0,0,-1);
183   GS.SetSeparator (',');
184   GS.SetEndMark   (';');
185   GS.SetSendName (new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.product")));
186   GS.SetFileName (new TCollection_HAsciiString("Filename.iges"));
187   GS.SetSystemId (new TCollection_HAsciiString(XSTEP_SYSTEM_VERSION));//#58 rln "MATRA-DATAVISION EUCLID-QUANTUM"
188   GS.SetInterfaceVersion (gsys);
189   GS.SetIntegerBits      ( IntegerSize() );
190   GS.SetMaxPower10Single ( RealLast10Exp() );
191   GS.SetMaxDigitsSingle  ( RealDigits() );
192   GS.SetMaxPower10Double ( RealLast10Exp() );
193   GS.SetMaxDigitsDouble  ( RealDigits() );
194   GS.SetReceiveName (Interface_Static::Static("write.iges.header.receiver")->HStringValue());
195 // new TCollection_HAsciiString("Unknown");
196   GS.SetScale       (1.0);
197   GS.SetUnitFlag    (Interface_Static::IVal("write.iges.unit"));
198   GS.SetUnitName    (new TCollection_HAsciiString(Interface_Static::CVal("write.iges.unit")));
199   GS.SetLineWeightGrad (1);
200   GS.SetMaxLineWeight  (0.01);
201   GS.SetDate        (datestr);
202   GS.SetResolution  (0.0001);
203   GS.SetMaxCoord    (0.0 /*1000.0*/);//22.10.98 rln BUC60081
204   GS.SetAuthorName  (Interface_Static::Static("write.iges.header.author")->HStringValue());
205 //  new TCollection_HAsciiString (process.UserName());
206   GS.SetCompanyName (Interface_Static::Static("write.iges.header.company")->HStringValue());
207 //  new TCollection_HAsciiString("Matra Datavision");
208   GS.SetIGESVersion (11);         // pour IGES-5.3 //gka 19.01.99
209   GS.SetDraftingStandard (0);
210   GS.SetLastChangeDate  (datestr);
211   GS.SetApplicationProtocol(new TCollection_HAsciiString("")); //gka 19.01.99
212
213 //  Interface_Check check;
214 //  GS.Init(params, check);
215
216   // Creating the Model
217   //-------------------
218
219   Handle(IGESData_IGESModel) model = new IGESData_IGESModel;
220   model->SetGlobalSection(GS);
221   Interface_InterfaceModel::SetTemplate ("iges", model);
222 }
223
224     Handle(IGESData_Protocol) IGESData::Protocol ()
225 {
226   return proto;
227 }