1 #include <HYDROData_Polyline.h>
2 #include <HYDROData_Iterator.h>
4 #include <TDataStd_Name.hxx>
5 #include <TDataStd_Integer.hxx>
6 #include <TDataStd_ByteArray.hxx>
7 #include <TDataStd_BooleanArray.hxx>
8 #include <TDataStd_IntegerArray.hxx>
9 #include <TDataStd_RealArray.hxx>
10 #include <TDataStd_ExtStringArray.hxx>
11 #include <TDataStd_UAttribute.hxx>
12 #include <TDF_ListIteratorOfLabelList.hxx>
14 #include <QPainterPath>
16 // tage of the child of my label that contains information about the operator
17 static const Standard_GUID GUID_MUST_BE_UPDATED("6647e1f7-1971-4c5a-86c7-11ff0291452d");
19 IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline, HYDROData_Object)
20 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline, HYDROData_Object)
22 HYDROData_Polyline::HYDROData_Polyline()
26 HYDROData_Polyline::~HYDROData_Polyline()
31 * Return polyline dimension
32 * \return polyline dimension. 2 or 3 is valid. 0 is invalid.
34 int HYDROData_Polyline::getDimension() const
36 Handle(TDataStd_Integer) aDim;
37 if(!myLab.FindAttribute(TDataStd_Integer::GetID(), aDim))
43 * Set polyline dimension. Should be 2 or 3.
44 * \param theDimension the polyline dimension
46 void HYDROData_Polyline::setDimension( int theDimension )
50 if( theDimension == 2 || theDimension == 3){
53 TDataStd_Integer::Set(myLab, aDim);
57 * Replace current polyline data by new sections list
58 * \param theSections the sections list
60 void HYDROData_Polyline::setPolylineData( const QList<PolylineSection>& theSections )
63 int aDim = getDimension();
69 if( theSections.size() == 0 )
71 int aSectionsSize = theSections.size();
75 TDF_Label aNameLab = myLab.FindChild(DataTag_SectionsName);
76 Handle(TDataStd_ExtStringArray) aSectsNameArray;
77 aSectsNameArray = TDataStd_ExtStringArray::Set(aNameLab, 0, aSectionsSize-1, false );
79 TDF_Label aSizeLab = myLab.FindChild(DataTag_SectionsSize);
80 Handle(TDataStd_IntegerArray) aSizeArray;
81 aSizeArray = TDataStd_IntegerArray::Set(aSizeLab, 0, aSectionsSize-1, false );
83 TDF_Label aClosedLab = myLab.FindChild(DataTag_SectionsClosed);
84 Handle(TDataStd_BooleanArray) aClosedArray;
85 aClosedArray = TDataStd_BooleanArray::Set(aClosedLab, 0, aSectionsSize-1 );
87 TDF_Label aTypeLab = myLab.FindChild(DataTag_SectionsType);
88 Handle(TDataStd_ByteArray) aTypeArray;
89 aTypeArray = TDataStd_ByteArray::Set(aTypeLab, 0, aSectionsSize-1, false );
91 //Extract sections parameters and count points
92 for( int i = 0 ; i < theSections.size() ; i++ ){
93 int aSectSize = theSections[i].myCoords.size();
94 aSectsNameArray->SetValue( i, theSections[i].mySectionName );
95 aSizeArray->SetValue( i, aSectSize );
96 aClosedArray->SetValue( i, theSections[i].myIsClosed );
97 char aType = (char)theSections[i].myType;
98 aTypeArray->SetValue( i, aType );
99 aPointsCnt += aSectSize;
101 //Don't create a points array
102 if( aPointsCnt == 0 )
105 Handle(TDataStd_RealArray) anArray;
106 anArray = TDataStd_RealArray::Set( myLab, 0, aPointsCnt*aDim - 1 );
108 for( int i = 0 ; i < theSections.size() ; i++ ){
109 for( int j = 0 ; j < theSections[i].myCoords.size() ; j++ ){
110 anArray->SetValue(aPtr, theSections[i].myCoords[j]);
117 * Return polyline data
118 * \return polyline section list
120 QList<PolylineSection> HYDROData_Polyline::getPolylineData()
123 QList<PolylineSection> aRes;
124 //Get sections size array handle
125 TDF_Label aLab = myLab.FindChild( DataTag_SectionsSize );
126 Handle(TDataStd_IntegerArray) aSizeArray;
127 if (!aLab.FindAttribute(TDataStd_IntegerArray::GetID(), aSizeArray))
128 return aRes; // return empty if no array
129 aSectCnt = aSizeArray->Length();
132 //Get section type array handle
133 aLab = myLab.FindChild( DataTag_SectionsType );
134 Handle(TDataStd_ByteArray) aTypeArray;
135 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aTypeArray))
137 int aLen = aTypeArray->Length();
138 if( aLen != aSectCnt )
140 //Get section closed array handle
141 aLab = myLab.FindChild( DataTag_SectionsClosed );
142 Handle(TDataStd_BooleanArray) aClosedArray;
143 if (!aLab.FindAttribute(TDataStd_BooleanArray::GetID(), aClosedArray))
145 aLen = aClosedArray->Length();
146 if( aLen != aSectCnt )
149 TDF_Label aNameLab = myLab.FindChild(DataTag_SectionsName);
150 Handle(TDataStd_ExtStringArray) aSectNamesArray;
151 if(!aNameLab.FindAttribute(TDataStd_ExtStringArray::GetID(), aSectNamesArray))
153 aLen = aSectNamesArray->Length();
154 if( aLen != aSectCnt )
156 //Get coordinates array
157 Handle(TDataStd_RealArray) aCoordsArray;
158 myLab.FindAttribute(TDataStd_RealArray::GetID(), aCoordsArray);
161 for( int i = 0 ; i < aSectCnt ; i++ ){
162 PolylineSection aSect;
163 aSect.myIsClosed = aClosedArray->Value(i);
164 aSect.myType = (PolylineSection::SectionType)aTypeArray->Value(i);
165 aSect.mySectionName = aSectNamesArray->Value(i);
166 int aSectSize = aSizeArray->Value(i);
167 for( int j = 0 ; j < aSectSize ; j++ ){
168 double aCoord = aCoordsArray->Value(aCoordPtr);
169 aSect.myCoords << aCoord;
178 * Remove all polyline attributes except dimension.
180 void HYDROData_Polyline::removeAll()
182 //Remove only section data
183 TDF_Label aLab = myLab.FindChild( DataTag_SectionsSize );
184 aLab.ForgetAllAttributes();
186 aLab = myLab.FindChild( DataTag_SectionsType );
187 aLab.ForgetAllAttributes();
189 aLab = myLab.FindChild( DataTag_SectionsClosed );
190 aLab.ForgetAllAttributes();
192 myLab.ForgetAttribute(TDataStd_RealArray::GetID());
197 * Return polyline painter path. Current implementation
198 * is ignored section type.
199 * \return polyline painter path.
201 QPainterPath HYDROData_Polyline::painterPath()
204 int aDim = getDimension();
205 if( ( aDim != 2 ) || ( aDim != 3) )
207 QList<PolylineSection> aSects = getPolylineData();
208 for( int i = 0 ; aSects.size() ; i++ ){
209 int aPntCnt = aSects[i].myCoords.size()/aDim;
211 aPath.moveTo(aSects[i].myCoords[0], aSects[i].myCoords[1] );
213 for( int j = 1 ; j < aPntCnt ; j++ ){
215 aPath.lineTo(aSects[i].myCoords[anIndx], aSects[i].myCoords[anIndx+1]);
217 if( aSects[i].myIsClosed ){
218 aPath.closeSubpath();