1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 //--------------------------------------------------------------------
17 //--------------------------------------------------------------------
19 #include <gp_Pnt2d.hxx>
21 #include <IGESData_DirChecker.hxx>
22 #include <IGESData_Dump.hxx>
23 #include <IGESData_IGESDumper.hxx>
24 #include <IGESData_IGESEntity.hxx>
25 #include <IGESData_IGESReaderData.hxx>
26 #include <IGESData_IGESWriter.hxx>
27 #include <IGESData_LineFontEntity.hxx>
28 #include <IGESData_ParamCursor.hxx>
29 #include <IGESData_ParamReader.hxx>
30 #include <IGESGeom_Flash.hxx>
31 #include <IGESGeom_ToolFlash.hxx>
32 #include <Interface_Check.hxx>
33 #include <Interface_CopyTool.hxx>
34 #include <Interface_EntityIterator.hxx>
35 #include <Interface_Macros.hxx>
36 #include <Interface_ShareTool.hxx>
37 #include <Message_Messenger.hxx>
38 #include <Standard_DomainError.hxx>
40 IGESGeom_ToolFlash::IGESGeom_ToolFlash () { }
43 void IGESGeom_ToolFlash::ReadOwnParams
44 (const Handle(IGESGeom_Flash)& ent,
45 const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
48 Standard_Real aDim1, aDim2, aRotation;
49 Handle(IGESData_IGESEntity) aReference;
50 Standard_Integer fn = ent->FormNumber(); // for default cases
52 //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
53 aDim1 = aDim2 = aRotation = 0.; // default values
55 // Reading reference of flash
56 PR.ReadXY(PR.CurrentList(1, 2), "Reference of Flash", aPoint); //szv#4:S4163:12Mar99 `st=` not needed
58 // Reading first flash sizing parameter
59 if (PR.DefinedElseSkip())
60 PR.ReadReal(PR.Current(), "First Flash sizing parameter", aDim1); //szv#4:S4163:12Mar99 `st=` not needed
61 else if (fn > 0) PR.AddFail("Fist Flash sizing parameter : undefined");
63 // Reading second flash sizing parameter
64 if (PR.DefinedElseSkip())
65 PR.ReadReal(PR.Current(), "Second Flash sizing parameter", aDim2); //szv#4:S4163:12Mar99 `st=` not needed
67 if (fn > 1) PR.AddFail("Second Flash sizing parameter : not defined");
70 // Reading rotation of flash about reference point
71 if (PR.DefinedElseSkip())
72 PR.ReadReal(PR.Current(), "Rotation about ref. point", aRotation); //szv#4:S4163:12Mar99 `st=` not needed
74 if (fn == 2 || fn == 4) PR.AddFail("Rotation about ref. point : not defined");
77 if ( PR.IsParamEntity(PR.CurrentNumber()) )
78 // Reading the referenced entity
79 PR.ReadEntity(IR, PR.Current(), "Referenced entity", aReference); //szv#4:S4163:12Mar99 `st=` not needed
80 // "else" not necessary as this is the last field
82 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
83 ent->Init (aPoint, aDim1, aDim2, aRotation, aReference);
86 void IGESGeom_ToolFlash::WriteOwnParams
87 (const Handle(IGESGeom_Flash)& ent, IGESData_IGESWriter& IW) const
89 IW.Send( ent->ReferencePoint().X() );
90 IW.Send( ent->ReferencePoint().Y() );
91 IW.Send( ent->Dimension1() );
92 IW.Send( ent->Dimension2() );
93 IW.Send( ent->Rotation() );
94 IW.Send( ent->ReferenceEntity() );
97 void IGESGeom_ToolFlash::OwnShared
98 (const Handle(IGESGeom_Flash)& ent, Interface_EntityIterator& iter) const
100 iter.GetOneItem( ent->ReferenceEntity() );
103 void IGESGeom_ToolFlash::OwnCopy
104 (const Handle(IGESGeom_Flash)& another,
105 const Handle(IGESGeom_Flash)& ent, Interface_CopyTool& TC) const
107 gp_XY aPoint = (another->ReferencePoint()).XY();
108 Standard_Real aDim1 = another->Dimension1();
109 Standard_Real aDim2 = another->Dimension2();
110 Standard_Real aRotation = another->Rotation();
112 DeclareAndCast(IGESData_IGESEntity, aReference,
113 TC.Transferred(another->ReferenceEntity()));
115 ent->Init(aPoint, aDim1, aDim2, aRotation, aReference);
118 Standard_Boolean IGESGeom_ToolFlash::OwnCorrect
119 (const Handle(IGESGeom_Flash)& ent) const
121 Standard_Integer fn = ent->FormNumber();
122 Standard_Boolean res0 = (ent->RankLineFont() != 1);
124 Handle(IGESData_LineFontEntity) nulfont;
125 ent->InitLineFont(nulfont,1); // ranklinefont force a 1
127 Standard_Boolean res1 = Standard_False;
128 Handle(IGESData_IGESEntity) ref = ent->ReferenceEntity();
129 if (fn != 0 && !ref.IsNull()) {
131 res1 = Standard_True;
133 Standard_Real d1 = ent->Dimension1();
134 Standard_Real d2 = ent->Dimension2();
135 Standard_Real rt = ent->Rotation();
136 if (fn == 0 && d1 != 0.) { d1 = 0.; res1 = Standard_True; }
137 if (fn <= 1 && d2 != 0.) { d2 = 0.; res1 = Standard_True; }
138 if ((fn <= 1 || fn == 3) && rt != 0.) { rt = 0.; res1 = Standard_True; }
139 if (res1) ent->Init (ent->ReferencePoint().XY(), d1, d2, rt, ref);
140 return (res0 || res1);
143 IGESData_DirChecker IGESGeom_ToolFlash::DirChecker
144 (const Handle(IGESGeom_Flash)& /* ent */ ) const
146 IGESData_DirChecker DC(125, 0, 4);
147 DC.Structure(IGESData_DefVoid);
148 DC.LineFont(IGESData_DefValue);
149 // DC.LineWeight(IGESData_DefValue);
150 DC.Color(IGESData_DefAny);
151 DC.HierarchyStatusRequired(0);
155 void IGESGeom_ToolFlash::OwnCheck
156 (const Handle(IGESGeom_Flash)& ent,
157 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
159 Standard_Integer fn = ent->FormNumber();
160 if (ent->RankLineFont() != 1)
161 ach->AddFail("LineFontPattern : Value != 1");
162 if (ent->ReferenceEntity().IsNull()) {
164 ach->AddFail("Flash defined by a Reference Entity, which is absent");
166 else if (fn != 0) ach->AddWarning("Reference Entity present though useless");
167 if (fn == 1 && ent->Dimension2() != 0.)
168 ach->AddWarning("Dimension 2 present though useless");
169 if ((fn == 1 || fn == 3) && ent->Rotation() != 0.)
170 ach->AddWarning("Rotation present though useless");
174 void IGESGeom_ToolFlash::OwnDump
175 (const Handle(IGESGeom_Flash)& ent, const IGESData_IGESDumper& dumper,
176 Standard_OStream& S, const Standard_Integer level) const
178 Standard_Integer sublevel = (level <= 4) ? 0 : 1;
179 Standard_Integer fn = ent->FormNumber();
181 S << "IGESGeom_Flash\n";
183 case 0 : S << " -- Form defined by reference entity --\n"; break;
184 case 1 : S << " -- Circular -- "; break;
185 case 2 : S << " -- Rectangle -- "; break;
186 case 3 : S << " -- Donut -- "; break;
187 case 4 : S << " -- Canoe -- "; break;
191 S << "Flash reference point : ";
192 IGESData_DumpXYL(S,level, ent->ReferencePoint(), ent->Location());
193 S << " First sizing parameter : " << ent->Dimension1() << " "
194 << " Second sizing parameter : " << ent->Dimension2() << "\n"
195 << " Rotation about reference entity : " << ent->Rotation() << "\n"
196 << "Reference Entity : ";
197 dumper.Dump(ent->ReferenceEntity(),S, sublevel);