0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / IGESDraw / IGESDraw_ToolSegmentedViewsVisible.cxx
1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 //--------------------------------------------------------------------
17 //--------------------------------------------------------------------
18
19 #include <IGESBasic_HArray1OfLineFontEntity.hxx>
20 #include <IGESData_DirChecker.hxx>
21 #include <IGESData_IGESDumper.hxx>
22 #include <IGESData_IGESReaderData.hxx>
23 #include <IGESData_IGESWriter.hxx>
24 #include <IGESData_LineFontEntity.hxx>
25 #include <IGESData_ParamReader.hxx>
26 #include <IGESDraw_SegmentedViewsVisible.hxx>
27 #include <IGESDraw_ToolSegmentedViewsVisible.hxx>
28 #include <IGESGraph_Color.hxx>
29 #include <IGESGraph_HArray1OfColor.hxx>
30 #include <Interface_Check.hxx>
31 #include <Interface_CopyTool.hxx>
32 #include <Interface_EntityIterator.hxx>
33 #include <Interface_Macros.hxx>
34 #include <Interface_ShareTool.hxx>
35 #include <TColStd_HArray1OfInteger.hxx>
36 #include <TColStd_HArray1OfReal.hxx>
37
38 IGESDraw_ToolSegmentedViewsVisible::IGESDraw_ToolSegmentedViewsVisible ()  {  }
39
40
41 void IGESDraw_ToolSegmentedViewsVisible::ReadOwnParams
42   (const Handle(IGESDraw_SegmentedViewsVisible)& ent,
43    const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
44 {
45   //Standard_Boolean                              st; //szv#4:S4163:12Mar99 moved down
46   Standard_Integer                              nbval;
47
48   Handle(IGESDraw_HArray1OfViewKindEntity) views; 
49   Handle(TColStd_HArray1OfReal)             breakpointParameters; 
50   Handle(TColStd_HArray1OfInteger)          displayFlags;
51   Handle(TColStd_HArray1OfInteger)          colorValues;
52   Handle(IGESGraph_HArray1OfColor)          colorDefinitions;
53   Handle(TColStd_HArray1OfInteger)          lineFontValues;
54   Handle(IGESBasic_HArray1OfLineFontEntity) lineFontDefinitions;
55   Handle(TColStd_HArray1OfInteger)          lineWeights;
56
57   // Reading nbval(Integer)
58   Standard_Boolean st = PR.ReadInteger( PR.Current(), "No. of View/segment blocks", nbval );
59   if (st && nbval > 0) {
60     views                = new IGESDraw_HArray1OfViewKindEntity(1, nbval);
61     breakpointParameters = new TColStd_HArray1OfReal(1, nbval);
62     displayFlags         = new TColStd_HArray1OfInteger(1, nbval);
63     colorValues          = new TColStd_HArray1OfInteger(1, nbval);
64     colorDefinitions     = new IGESGraph_HArray1OfColor(1, nbval);
65     lineFontValues       = new TColStd_HArray1OfInteger(1, nbval);
66     lineFontDefinitions  = new IGESBasic_HArray1OfLineFontEntity(1, nbval);
67     lineWeights          = new TColStd_HArray1OfInteger(1, nbval);
68     
69     Handle(IGESData_ViewKindEntity) tempView;
70     Standard_Real                   tempBreak;
71     Standard_Integer                tempDisplay;
72     Standard_Integer                tempColorValue;
73     Handle(IGESGraph_Color)         tempColorDef;
74     Standard_Integer                tempLineFontValue;
75     Handle(IGESData_LineFontEntity) tempLineFontDef;
76     Standard_Integer                tempLine;
77     
78     for (Standard_Integer i = 1; i <= nbval; i++)
79       {
80         // Reading views(HArray1OfView)
81         //st = PR.ReadEntity( IR, PR.Current(), "Instance of views",
82                              //STANDARD_TYPE(IGESData_ViewKindEntity), tempView ); //szv#4:S4163:12Mar99 moved in if
83         if (PR.ReadEntity(IR, PR.Current(), "Instance of views",
84                           STANDARD_TYPE(IGESData_ViewKindEntity), tempView))
85           views->SetValue(i, tempView);
86         
87         // Reading breakpointParameters(HArray1OfReal)
88         //st = PR.ReadReal(PR.Current(), "array breakpointParameters", tempBreak ); //szv#4:S4163:12Mar99 moved in if
89         if (PR.ReadReal(PR.Current(), "array breakpointParameters", tempBreak ))
90           breakpointParameters->SetValue(i, tempBreak);
91         
92         // Reading displayFlags(HArray1OfInteger)
93         //st = PR.ReadInteger( PR.Current(), "array displayFlags", tempDisplay ); //szv#4:S4163:12Mar99 moved in if
94         if (PR.ReadInteger( PR.Current(), "array displayFlags", tempDisplay ))
95           displayFlags->SetValue(i, tempDisplay);
96
97         Standard_Integer curnum = PR.CurrentNumber();
98
99         //  Reading Color : Value (>0) or Definition (<0 = D.E. Pointer)
100         PR.ReadInteger( PR.Current(), "array colorValues", tempColorValue); //szv#4:S4163:12Mar99 `st=` not needed
101         if (tempColorValue < 0) {
102           colorValues->SetValue(i, -1);
103           tempColorDef = GetCasted(IGESGraph_Color,PR.ParamEntity(IR,curnum));
104           if (tempColorDef.IsNull()) PR.AddFail
105             ("A Color Definition Entity is incorrect");
106           else  colorDefinitions->SetValue(i, tempColorDef);
107         }
108         else
109           colorValues->SetValue(i, tempColorValue);
110
111         curnum = PR.CurrentNumber();
112         //  Reading Line Font : Value (>0) or Definition (<0 = D.E. Pointer)
113         PR.ReadInteger( PR.Current(), "array lineFontValues", tempLineFontValue ); //szv#4:S4163:12Mar99 `st=` not needed
114         if (tempLineFontValue < 0 ) {
115           lineFontValues->SetValue(i, -1);
116           tempLineFontDef = GetCasted(IGESData_LineFontEntity,
117                                       PR.ParamEntity(IR,curnum));
118           if (tempLineFontDef.IsNull()) PR.AddFail
119             ("A Line Font Definition Entity is incorrect");
120           lineFontDefinitions->SetValue(i,tempLineFontDef);
121         }
122         else
123           lineFontValues->SetValue(i, tempLineFontValue);
124         
125         // Reading lineWeights(HArray1OfInteger)
126         //st = PR.ReadInteger( PR.Current(), "array lineWeights", tempLine ); //szv#4:S4163:12Mar99 moved in if
127         if (PR.ReadInteger( PR.Current(), "array lineWeights", tempLine ))
128           lineWeights->SetValue(i, tempLine);
129       }
130   }
131   else
132     PR.AddFail("No. of View/segment blocks : Not Positive");
133
134   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
135   ent->Init
136     (views, breakpointParameters, displayFlags,colorValues, colorDefinitions,
137      lineFontValues, lineFontDefinitions, lineWeights);
138 }
139
140 void IGESDraw_ToolSegmentedViewsVisible::WriteOwnParams
141   (const Handle(IGESDraw_SegmentedViewsVisible)& ent, IGESData_IGESWriter& IW)  const
142 {
143   Standard_Integer Up  = ent->NbSegmentBlocks();
144   IW.Send( Up );
145   for ( Standard_Integer i = 1; i <= Up; i++)
146     {
147       IW.Send( ent->ViewItem(i) );
148       IW.Send( ent->BreakpointParameter(i) );
149       IW.Send( ent->DisplayFlag(i) );
150
151       if (ent->IsColorDefinition(i))
152         IW.Send( ent->ColorDefinition(i), Standard_True );     // negative
153       else
154         IW.Send( ent->ColorValue(i) );
155
156       if (ent->IsFontDefinition(i))
157         IW.Send( ent->LineFontDefinition(i), Standard_True );  // negative
158       else
159         IW.Send( ent->LineFontValue(i) );
160
161       IW.Send( ent->LineWeightItem(i) );
162     }
163 }
164
165 void  IGESDraw_ToolSegmentedViewsVisible::OwnShared
166   (const Handle(IGESDraw_SegmentedViewsVisible)& ent, Interface_EntityIterator& iter) const
167 {
168   Standard_Integer Up  = ent->NbSegmentBlocks();
169   for ( Standard_Integer i = 1; i <= Up; i++)
170     {
171       iter.GetOneItem( ent->ViewItem(i) );
172       if (ent->IsColorDefinition(i))
173         iter.GetOneItem( ent->ColorDefinition(i) );
174       if (!ent->IsFontDefinition(i))
175         iter.GetOneItem( ent->LineFontDefinition(i) );
176     }
177 }
178
179 void IGESDraw_ToolSegmentedViewsVisible::OwnCopy
180   (const Handle(IGESDraw_SegmentedViewsVisible)& another,
181    const Handle(IGESDraw_SegmentedViewsVisible)& ent, Interface_CopyTool& TC) const
182 {
183   Standard_Integer                              nbval;
184   Handle(IGESDraw_HArray1OfViewKindEntity) views;
185   Handle(TColStd_HArray1OfReal)          breakpointParameters;
186   Handle(TColStd_HArray1OfInteger)       displayFlags;
187   Handle(TColStd_HArray1OfInteger)       colorValues;
188   Handle(IGESGraph_HArray1OfColor)          colorDefinitions;
189   Handle(TColStd_HArray1OfInteger)       lineFontValues;
190   Handle(IGESBasic_HArray1OfLineFontEntity) lineFontDefinitions;
191   Handle(TColStd_HArray1OfInteger)       lineWeights;
192  
193   Handle(IGESData_ViewKindEntity)               retView; 
194   Handle(IGESGraph_Color)                       retColorDef; 
195   Handle(IGESData_LineFontEntity)               retLineFontDef; 
196  
197   nbval                = another->NbSegmentBlocks();
198   views                = new IGESDraw_HArray1OfViewKindEntity(1, nbval);
199   breakpointParameters = new TColStd_HArray1OfReal(1, nbval);
200   displayFlags         = new TColStd_HArray1OfInteger(1, nbval);
201   colorValues          = new TColStd_HArray1OfInteger(1, nbval);
202   lineFontValues       = new TColStd_HArray1OfInteger(1, nbval);
203   colorDefinitions     = new IGESGraph_HArray1OfColor(1, nbval);
204   lineFontDefinitions  = new IGESBasic_HArray1OfLineFontEntity(1, nbval);
205   lineWeights          = new TColStd_HArray1OfInteger(1, nbval);
206  
207   for (Standard_Integer i = 1; i <= nbval; i++)
208     {
209       retView = another->ViewItem(i);
210       DeclareAndCast(IGESData_ViewKindEntity,
211                      tempView, TC.Transferred(retView));
212       views->SetValue( i, tempView );
213  
214       breakpointParameters->SetValue( i, another->BreakpointParameter(i) );
215  
216       displayFlags->SetValue( i, another->DisplayFlag(i) );
217  
218       if ( another->IsColorDefinition(i) )
219         {
220           retColorDef = another->ColorDefinition(i);
221           DeclareAndCast(IGESGraph_Color, tempColorDef, 
222                          TC.Transferred(retColorDef));
223           colorDefinitions->SetValue( i, tempColorDef );
224         }
225       else
226         {
227           colorValues->SetValue( i, another->ColorValue(i) );
228 ////          colorDefinitions->SetValue( i, NULL );    par defaut
229         }
230  
231       if ( another->IsFontDefinition(i) )
232         {
233           retLineFontDef = another->LineFontDefinition(i);
234           DeclareAndCast(IGESData_LineFontEntity, tempLineFontDef, 
235                          TC.Transferred(retLineFontDef));
236           lineFontDefinitions->SetValue( i, tempLineFontDef );
237         }
238       else
239         {
240           lineFontValues->SetValue( i, another->LineFontValue(i) );
241 ////          lineFontDefinitions->SetValue( i, NULL );  par defaut
242         }
243  
244       lineWeights->SetValue( i, another->LineWeightItem(i) );
245     }
246
247   ent->Init(views, breakpointParameters, displayFlags,
248             colorValues, colorDefinitions,
249             lineFontValues, lineFontDefinitions, lineWeights);
250 }
251
252 IGESData_DirChecker IGESDraw_ToolSegmentedViewsVisible::DirChecker
253   (const Handle(IGESDraw_SegmentedViewsVisible)& /*ent*/)  const
254
255   IGESData_DirChecker DC (402, 19);
256   DC.Structure(IGESData_DefVoid);
257   DC.LineFont(IGESData_DefVoid);
258   DC.LineWeight(IGESData_DefVoid);
259   DC.Color(IGESData_DefVoid);
260   DC.BlankStatusIgnored();
261   DC.SubordinateStatusRequired(0);
262   DC.UseFlagRequired(1);
263   DC.HierarchyStatusIgnored();
264   return DC;
265 }
266
267 void IGESDraw_ToolSegmentedViewsVisible::OwnCheck
268   (const Handle(IGESDraw_SegmentedViewsVisible)& /*ent*/,
269    const Interface_ShareTool& , Handle(Interface_Check)& /*ach*/)  const
270 {
271 }
272
273 void IGESDraw_ToolSegmentedViewsVisible::OwnDump
274   (const Handle(IGESDraw_SegmentedViewsVisible)& ent, const IGESData_IGESDumper& dumper,
275    Standard_OStream& S, const Standard_Integer level)  const
276 {
277   Standard_Integer sublevel = (level <= 4) ? 0 : 1;
278
279   S << "IGESDraw_SegmentedViewsVisible\n"
280     << "View Entities            :\n"
281     << "Breakpoint parameters    :\n"
282     << "Display flags            :\n"
283     << "Color Values             :\n"
284     << "Color Definitions        :\n"
285     << "LineFont Values          :\n"
286     << "LineFont Definitions     :\n"
287     << "Line Weights :\n"
288     << "Count Of Blocks = "      << ent->NbSegmentBlocks() << "\n";
289   switch (level)
290     {
291     case 4 : S << " [ for content, ask level > 4 ]\n";
292       break; // Nothing to be dumped here
293     case 5 :        // Presently level 5 and 6 have the same Dump
294     case 6 :
295       {
296         Standard_Integer I;
297         Standard_Integer up  = ent->NbSegmentBlocks();
298         for (I = 1; I <= up; I++)
299           {
300             S << "[" << I << "]:\n"
301               << "View Entity : ";
302             dumper.Dump (ent->ViewItem(I),S, sublevel);
303             S << "\n"
304               << "Breakpoint parameter : " <<ent->BreakpointParameter(I)<< "\n"
305               << "Display Flag : " << ent->DisplayFlag(I) << "\n";
306             if ( (ent->ColorDefinition(I)).IsNull() )
307               {
308                 S << "Color Value : " << ent->ColorValue(I);
309               }
310             else
311               {
312                 S << "Color Definition : ";
313                 dumper.Dump (ent->ColorDefinition(I),S, sublevel);
314               }
315             S << "\n";
316             if ( (ent->LineFontDefinition(I)).IsNull() )
317               {
318                 S << "LineFont Value : " << ent->LineFontValue(I);
319               }
320             else
321               {
322                 S << "LineFont Definition : ";
323                 dumper.Dump (ent->LineFontDefinition(I),S, sublevel);
324               }
325             S << "\n"
326               << "Line Weight : " << ent->LineWeightItem(I) << "\n";
327           }
328       }
329       break;
330     }
331   S << std::endl;
332 }