Salome HOME
dumping to py, sip, translations
[modules/hydro.git] / src / HYDROData / HYDROData_BCPolygon.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROData_BCPolygon.h"
20
21 //#include "HYDROData_IAltitudeObject.h"
22 #include "HYDROData_Document.h"
23 //#include "HYDROData_ShapesGroup.h"
24 #include "HYDROData_PolylineXY.h"
25 #include "HYDROData_ShapesTool.h"
26
27 #include <TopoDS.hxx>
28 #include <TopTools_ListIteratorOfListOfShape.hxx>
29 #include <TopTools_HSequenceOfShape.hxx>
30 #include <TDataStd_Integer.hxx>
31
32 #include <HYDROData_Tool.h>
33
34 #include <QColor>
35 #include <QStringList>
36
37 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_BCPolygon,HYDROData_Object)
38
39
40 HYDROData_BCPolygon::HYDROData_BCPolygon()
41 : HYDROData_Object( Geom_2d )
42 {
43 }
44
45 HYDROData_BCPolygon::~HYDROData_BCPolygon()
46 {
47 }
48
49 QStringList HYDROData_BCPolygon::DumpToPython( const QString& thePyScriptPath,
50                                                MapOfTreatedObjects& theTreatedObjects ) const
51 {
52   QStringList aResList = dumpObjectCreation( theTreatedObjects );
53   
54   QString aBCName = GetObjPyName();
55
56   Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
57   setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
58
59   int nType = GetBoundaryType();
60   aResList << QString( "%1.SetBoundaryType(%2)" ).arg(aBCName).arg(nType);
61
62   aResList << QString( "" );
63
64   aResList << QString( "%1.Update()" ).arg( aBCName );
65   aResList << QString( "" );
66
67   return aResList;
68 }
69
70 HYDROData_SequenceOfObjects HYDROData_BCPolygon::GetAllReferenceObjects() const
71 {
72   HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
73
74   Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
75   if ( !aRefPolyline.IsNull() )
76     aResSeq.Append( aRefPolyline );
77
78   return aResSeq;
79 }
80
81 int HYDROData_BCPolygon::GetBoundaryType() const
82 {
83   Handle(TDataStd_Integer) aBoundaryTypeAttr;
84
85   int aBoundaryTypeVal = 0; //default
86   if( myLab.FindAttribute(TDataStd_Integer::GetID(), aBoundaryTypeAttr ) )
87     aBoundaryTypeVal = aBoundaryTypeAttr->Get();
88   return aBoundaryTypeVal;
89 }
90
91 void HYDROData_BCPolygon::SetBoundaryType( int theBoundaryType ) const
92 {
93   TDataStd_Integer::Set( myLab, theBoundaryType );
94 }
95
96 void HYDROData_BCPolygon::Update()
97 {
98   HYDROData_Object::Update();
99   SetTopShape( generateTopShape() );
100 }
101
102 void HYDROData_BCPolygon::Update(const TopoDS_Shape& theTopShape)
103 {
104   HYDROData_Object::Update();
105   SetTopShape( theTopShape);
106 }
107
108 bool HYDROData_BCPolygon::IsHas2dPrs() const
109 {
110   return true;
111 }
112
113 TopoDS_Shape HYDROData_BCPolygon::generateTopShape() const
114 {
115   return generateTopShape( GetPolyline() );
116 }
117
118 TopoDS_Shape HYDROData_BCPolygon::generateTopShape( const Handle(HYDROData_PolylineXY)& aPolyline )
119 {
120   return HYDROData_Tool::PolyXY2Face(aPolyline);
121 }
122
123 TopoDS_Shape HYDROData_BCPolygon::GetShape3D() const
124 {
125   return GetTopShape();
126 }
127
128 QColor HYDROData_BCPolygon::DefaultFillingColor() const
129 {
130   int aBT = GetBoundaryType();
131   QColor aFC;
132   if (aBT == 1)
133     aFC = QColor( Qt::blue );
134   else if (aBT == 2)
135     aFC = QColor( Qt::darkGreen );
136   else if (aBT == 3)
137     aFC = QColor( Qt::darkYellow );
138   else 
139     aFC = QColor( Qt::red );
140   //aFC.setAlpha(175);
141   return aFC;
142 }
143
144 QColor HYDROData_BCPolygon::DefaultBorderColor() const
145 {
146   return QColor( Qt::black );
147 }
148
149 void HYDROData_BCPolygon::SetPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
150 {
151   if( IsEqual( GetPolyline(), thePolyline ) )
152     return;
153
154   SetReferenceObject( thePolyline, DataTag_Polyline );
155   Changed( Geom_2d );
156 }
157
158 Handle(HYDROData_PolylineXY) HYDROData_BCPolygon::GetPolyline() const
159 {
160   return Handle(HYDROData_PolylineXY)::DownCast( 
161            GetReferenceObject( DataTag_Polyline ) );
162 }
163
164 void HYDROData_BCPolygon::RemovePolyline()
165 {
166   ClearReferenceObjects( DataTag_Polyline );
167   Changed( Geom_2d );
168 }