08399d3c574ca65c3ce1f375e394dd56a3095ac0
[occt.git] / src / IGESDraw / IGESDraw_ToolPerspectiveView.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 <gp_Pnt.hxx>
20 #include <gp_Vec.hxx>
21 #include <gp_XY.hxx>
22 #include <gp_XYZ.hxx>
23 #include <IGESData_DirChecker.hxx>
24 #include <IGESData_Dump.hxx>
25 #include <IGESData_IGESDumper.hxx>
26 #include <IGESData_IGESReaderData.hxx>
27 #include <IGESData_IGESWriter.hxx>
28 #include <IGESData_ParamCursor.hxx>
29 #include <IGESData_ParamReader.hxx>
30 #include <IGESData_TransfEntity.hxx>
31 #include <IGESDraw_PerspectiveView.hxx>
32 #include <IGESDraw_ToolPerspectiveView.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
41 IGESDraw_ToolPerspectiveView::IGESDraw_ToolPerspectiveView ()    {  }
42
43
44 void IGESDraw_ToolPerspectiveView::ReadOwnParams
45   (const Handle(IGESDraw_PerspectiveView)& ent,
46    const Handle(IGESData_IGESReaderData)& /*IR*/, IGESData_ParamReader& PR) const
47 {
48   //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
49
50   gp_XY tempTopLeft, tempBottomRight;
51   Standard_Real tempLeft, tempRight, tempTop, tempBottom;
52   gp_XYZ tempCenterOfProjection, tempViewUpVector;
53   gp_XYZ tempViewNormalVector, tempViewReferencePoint;
54   Standard_Integer tempViewNumber, tempDepthClip;
55   Standard_Real tempScaleFactor, tempViewPlaneDistance;
56   Standard_Real tempBackPlaneDistance, tempFrontPlaneDistance;
57
58   //szv#4:S4163:12Mar99 `st=` not needed
59   PR.ReadInteger(PR.Current(), "View Number", tempViewNumber);
60   PR.ReadReal(PR.Current(), "Scale Number", tempScaleFactor);
61   PR.ReadXYZ(PR.CurrentList(1, 3), "View Plane Normal Vector", tempViewNormalVector);
62   PR.ReadXYZ(PR.CurrentList(1, 3), "View Reference Point", tempViewReferencePoint);
63   PR.ReadXYZ(PR.CurrentList(1, 3), "Center Of Projection", tempCenterOfProjection);
64   PR.ReadXYZ(PR.CurrentList(1, 3), "View Up Vector", tempViewUpVector);
65   PR.ReadReal(PR.Current(), "View Plane Distance", tempViewPlaneDistance);
66
67   //st = PR.ReadReal(PR.Current(), "Left Side Of Clipping Window", tempLeft); //szv#4:S4163:12Mar99 moved in if
68   if (PR.ReadReal(PR.Current(), "Left Side Of Clipping Window", tempLeft))
69     tempTopLeft.SetX(tempLeft);
70
71   //st = PR.ReadReal(PR.Current(), "Right Side Of Clipping Window", tempRight); //szv#4:S4163:12Mar99 moved in if
72   if (PR.ReadReal(PR.Current(), "Right Side Of Clipping Window", tempRight))
73     tempBottomRight.SetX(tempRight);
74
75   //st = PR.ReadReal(PR.Current(), "Bottom Of Clipping Window", tempBottom); //szv#4:S4163:12Mar99 moved in if
76   if (PR.ReadReal(PR.Current(), "Bottom Of Clipping Window", tempBottom))
77     tempBottomRight.SetY(tempBottom);
78
79   //st = PR.ReadReal(PR.Current(), "Top Of Clipping Window", tempTop); //szv#4:S4163:12Mar99 moved in if
80   if (PR.ReadReal(PR.Current(), "Top Of Clipping Window", tempTop))
81     tempTopLeft.SetY(tempTop);
82
83   //szv#4:S4163:12Mar99 `st=` not needed
84   PR.ReadInteger(PR.Current(), "Depth Clipping Indicator", tempDepthClip);
85   PR.ReadReal(PR.Current(), "Back Plane Distance", tempBackPlaneDistance);
86   PR.ReadReal(PR.Current(), "Front Plane Distance", tempFrontPlaneDistance);
87
88   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
89   ent->Init
90     (tempViewNumber, tempScaleFactor, tempViewNormalVector,
91      tempViewReferencePoint, tempCenterOfProjection, tempViewUpVector,
92      tempViewPlaneDistance, tempTopLeft, tempBottomRight, tempDepthClip,
93      tempBackPlaneDistance, tempFrontPlaneDistance);
94 }
95
96 void IGESDraw_ToolPerspectiveView::WriteOwnParams
97   (const Handle(IGESDraw_PerspectiveView)& ent, IGESData_IGESWriter& IW)  const
98 {
99   IW.Send(ent->ViewNumber());
100   IW.Send(ent->ScaleFactor());
101   IW.Send(ent->ViewNormalVector().X());
102   IW.Send(ent->ViewNormalVector().Y());
103   IW.Send(ent->ViewNormalVector().Z());
104   IW.Send(ent->ViewReferencePoint().X());
105   IW.Send(ent->ViewReferencePoint().Y());
106   IW.Send(ent->ViewReferencePoint().Z());
107   IW.Send(ent->CenterOfProjection().X());
108   IW.Send(ent->CenterOfProjection().Y());
109   IW.Send(ent->CenterOfProjection().Z());
110   IW.Send(ent->ViewUpVector().X());
111   IW.Send(ent->ViewUpVector().Y());
112   IW.Send(ent->ViewUpVector().Z());
113   IW.Send(ent->ViewPlaneDistance());
114   IW.Send(ent->TopLeft().X());
115   IW.Send(ent->BottomRight().X());
116   IW.Send(ent->BottomRight().Y());
117   IW.Send(ent->TopLeft().Y());
118   IW.Send(ent->DepthClip());
119   IW.Send(ent->BackPlaneDistance());
120   IW.Send(ent->FrontPlaneDistance());
121 }
122
123 void  IGESDraw_ToolPerspectiveView::OwnShared
124   (const Handle(IGESDraw_PerspectiveView)& /*ent*/, Interface_EntityIterator& /*iter*/) const
125 {
126 }
127
128 void IGESDraw_ToolPerspectiveView::OwnCopy
129   (const Handle(IGESDraw_PerspectiveView)& another,
130    const Handle(IGESDraw_PerspectiveView)& ent, Interface_CopyTool& /*TC*/) const
131 {
132   ent->Init
133     (another->ViewNumber(), another->ScaleFactor(),
134      another->ViewNormalVector().XYZ(),   another->ViewReferencePoint().XYZ(),
135      another->CenterOfProjection().XYZ(), another->ViewUpVector().XYZ(),
136      another->ViewPlaneDistance(),
137      another->TopLeft().XY(),another->BottomRight().XY(), another->DepthClip(),
138      another->BackPlaneDistance(), another->FrontPlaneDistance());
139 }
140
141
142 IGESData_DirChecker IGESDraw_ToolPerspectiveView::DirChecker
143   (const Handle(IGESDraw_PerspectiveView)& /*ent*/)  const
144 {
145   IGESData_DirChecker DC(410, 1);
146   DC.Structure(IGESData_DefVoid);
147   DC.LineFont(IGESData_DefVoid);
148   DC.LineWeight(IGESData_DefVoid);
149   DC.Color(IGESData_DefVoid);
150   DC.BlankStatusIgnored();
151   DC.UseFlagRequired(1);
152   DC.HierarchyStatusIgnored();
153
154   return DC;
155 }
156
157 void IGESDraw_ToolPerspectiveView::OwnCheck
158   (const Handle(IGESDraw_PerspectiveView)& ent,
159    const Interface_ShareTool& , Handle(Interface_Check)& ach)  const
160 {
161   if ((ent->DepthClip() < 0) || (ent->DepthClip() > 3))
162     ach->AddFail("DepthClip has invalid value");
163   if (ent->HasTransf()) {
164     if (ent->Transf()->FormNumber() != 0)
165       ach->AddFail("Associated Matrix has not Form Number 0");
166   }
167 }
168
169 void IGESDraw_ToolPerspectiveView::OwnDump
170   (const Handle(IGESDraw_PerspectiveView)& ent, const IGESData_IGESDumper& /*dumper*/,
171    Standard_OStream& S, const Standard_Integer level)  const
172 {
173   S << "IGESDraw_PerspectiveView\n"
174     << "View Number  : " << ent->ViewNumber()  << "  "
175     << "Scale Factor : " << ent->ScaleFactor() << "\n"
176     << "View Plane Normal Vector : ";
177   IGESData_DumpXYZL(S,level, ent->ViewNormalVector(), ent->Location());
178   S << "\nView Reference Point     : ";
179   IGESData_DumpXYZL(S,level, ent->ViewReferencePoint() , ent->Location());
180   S << "\nCenter Of Projection     : ";
181   IGESData_DumpXYZL(S,level, ent->CenterOfProjection() , ent->Location());
182   S << "\nView Up Vector           : ";
183   IGESData_DumpXYZL(S,level, ent->ViewUpVector() , ent->Location());
184   S << "\nView Plane Distance      : " << ent->ViewPlaneDistance()<< "\n"
185     << "Left   Side Of Clipping Window : " << ent->TopLeft().X()     << "\n"
186     << "Right  Side Of Clipping Window : " << ent->BottomRight().X() << "\n"
187     << "Bottom Side Of Clipping Window : " << ent->BottomRight().Y() << "\n"
188     << "Top    Side Of Clipping Window : " << ent->TopLeft().Y()     << "\n"
189     << "Depth Clipping : " << ent->DepthClip();
190   switch (ent->DepthClip()) {
191     case 0 :  S << " (No Depth Clipping)\n";                 break;
192     case 1 :  S << " (Back Clipping Plane ON)\n";            break;
193     case 2 :  S << " (Front Clipping Plane ON)\n";           break;
194     case 3 :  S << " (Front and Back Clipping Planes ON)\n"; break;
195     default : S << " (Invalid Value)\n";                     break;
196   }
197   S << "Back Plane Distance  : " << ent->BackPlaneDistance()  << "  "
198     << "Front Plane Distance : " << ent->FrontPlaneDistance() << "\n"
199     << std::endl;
200 }