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