1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_PrsObject_i.cxx
24 // Author : Alexey PETROV
27 #include "VISU_CutLinesPL.hxx"
28 #include "VISU_Result_i.hh"
29 #include "VISU_CutLines_i.hh"
30 #include "VISU_Actor.h"
32 #include "VISU_PipeLineUtils.hxx"
34 #include <vtkAppendPolyData.h>
40 static int MYDEBUG = 0;
41 static int MYDEBUGWITHFILES = 0;
43 static int MYDEBUG = 0;
44 static int MYDEBUGWITHFILES = 0;
47 int VISU::CutLines_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
48 const char* theFieldName, int theIteration)
50 return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration);
53 int VISU::CutLines_i::myNbPresent = 0;
54 QString VISU::CutLines_i::GenerateName() { return VISU::GenerateName("CutLines",myNbPresent++);}
56 const string VISU::CutLines_i::myComment = "CUTLINES";
57 const char* VISU::CutLines_i::GetComment() const { return myComment.c_str();}
59 VISU::CutLines_i::CutLines_i(Result_i* theResult, bool theAddToStudy) :
60 PrsObject_i(theResult->GetStudyDocument()),
62 ScalarMap_i(theResult, theAddToStudy)
67 void VISU::CutLines_i::Destroy(){
68 ScalarMap_i::Destroy();
71 void VISU::CutLines_i::SameAs(const CutLines_i* theOrigin){
72 CutLines_i* aCutLines = const_cast<CutLines_i*>(theOrigin);
73 VISU::ScalarMap_i::SameAs(theOrigin);
75 //SetNbLines(aCutLines->GetNbLines());
76 //SetDisplacement(aCutLines->GetDisplacement());
77 //SetDisplacement2(aCutLines->GetDisplacement2());
78 //SetOrientationType(aCutLines->GetOrientationType());
79 //SetOrientationType2(aCutLines->GetOrientationType2());
80 //SetRotateX(aCutLines->GetRotateX());
81 //SetRotateY(aCutLines->GetRotateY());
82 //SetRotateX2(aCutLines->GetRotateX2());
83 //SetRotateY2(aCutLines->GetRotateY2());
86 VISU::Storable* VISU::CutLines_i::Create(const char* theMeshName, VISU::Entity theEntity,
87 const char* theFieldName, int theIteration)
89 return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
92 VISU::Storable* VISU::CutLines_i::Restore(const Storable::TRestoringMap& theMap)
93 throw(std::logic_error&)
95 ScalarMap_i::Restore(theMap);
96 SetNbLines(VISU::Storable::FindValue(theMap,"myNbLines").toInt());
97 SetDisplacement(VISU::Storable::FindValue(theMap,"myDisplacement[0]").toDouble());
98 SetDisplacement2(VISU::Storable::FindValue(theMap,"myDisplacement[1]").toDouble());
99 SetOrientationType(VISU::CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[0]").toInt()));
100 SetOrientationType(VISU::CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[1]").toInt()));
101 SetRotateX(VISU::Storable::FindValue(theMap,"aRot[0][0]").toDouble());
102 SetRotateY(VISU::Storable::FindValue(theMap,"aRot[0][1]").toDouble());
103 SetRotateX2(VISU::Storable::FindValue(theMap,"aRot[1][0]").toDouble());
104 SetRotateY2(VISU::Storable::FindValue(theMap,"aRot[1][1]").toDouble());
109 void VISU::CutLines_i::ToStream(std::ostringstream& theStr){
110 ScalarMap_i::ToStream(theStr);
111 Storable::DataToStream( theStr, "myNbLines", int(GetNbLines()) );
112 Storable::DataToStream( theStr, "myDisplacement[0]", GetDisplacement() );
113 Storable::DataToStream( theStr, "myDisplacement[1]", GetDisplacement2() );
114 Storable::DataToStream( theStr, "myBasePlane[0]", int(GetOrientationType()) );
115 Storable::DataToStream( theStr, "myBasePlane[1]", int(GetOrientationType2()) );
116 Storable::DataToStream( theStr, "aRot[0][0]", GetRotateX() );
117 Storable::DataToStream( theStr, "aRot[0][1]", GetRotateY() );
118 Storable::DataToStream( theStr, "aRot[1][0]", GetRotateX2() );
119 Storable::DataToStream( theStr, "aRot[1][1]", GetRotateY2() );
122 VISU::Storable* VISU::CutLines_i::Restore(SALOMEDS::SObject_ptr theSObject,
123 const string& thePrefix, const Storable::TRestoringMap& theMap)
124 throw(std::logic_error&)
126 VISU::Result_i* pResult = GetResult(theSObject);
128 VISU::CutLines_i* pResent = new VISU::CutLines_i(pResult);
129 return pResent->Restore(theMap);
135 VISU::CutLines_i::~CutLines_i(){
136 if(MYDEBUG) MESSAGE("CutLines_i::~CutLines_i()");
140 void VISU::CutLines_i::SetOrientationType(VISU::CutPlanes::Orientation theOrient){
141 myCutLinesPL->SetPlaneOrientation(VISU_CutPlanesPL::PlaneOrientation(theOrient));
143 void VISU::CutLines_i::SetOrientationType2(VISU::CutPlanes::Orientation theOrient){
144 myCutLinesPL->SetPlaneOrientation(VISU_CutPlanesPL::PlaneOrientation(theOrient),1);
147 VISU::CutPlanes::Orientation VISU::CutLines_i::GetOrientationType() {
148 return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation());
150 VISU::CutPlanes::Orientation VISU::CutLines_i::GetOrientationType2() {
151 return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation(1));
155 void VISU::CutLines_i::SetDisplacement(CORBA::Double theDisp) {
156 myCutLinesPL->SetDisplacement(theDisp);
158 void VISU::CutLines_i::SetDisplacement2(CORBA::Double theDisp) {
159 myCutLinesPL->SetDisplacement(theDisp,1);
162 CORBA::Double VISU::CutLines_i::GetDisplacement() {
163 return myCutLinesPL->GetDisplacement();
165 CORBA::Double VISU::CutLines_i::GetDisplacement2() {
166 return myCutLinesPL->GetDisplacement(1);
170 void VISU::CutLines_i::SetBasePlanePosition(CORBA::Double thePlanePosition){
171 myCutLinesPL->SetPosition(thePlanePosition);
174 CORBA::Double VISU::CutLines_i::GetBasePlanePosition(){
175 return myCutLinesPL->GetPosition();
178 void VISU::CutLines_i::SetLinePosition(CORBA::Long thePlaneNumber, CORBA::Double thePlanePosition){
179 myCutLinesPL->SetPartPosition(thePlaneNumber,thePlanePosition);
182 CORBA::Double VISU::CutLines_i::GetLinePosition(CORBA::Long thePlaneNumber){
183 return myCutLinesPL->GetPartPosition(thePlaneNumber,1);
187 void VISU::CutLines_i::SetDefault(){
188 myCutLinesPL->SetDefault();
191 CORBA::Boolean VISU::CutLines_i::IsDefault(){
192 return myCutLinesPL->IsDefault();
195 void VISU::CutLines_i::SetDefaultPosition(CORBA::Long thePlaneNumber){
196 myCutLinesPL->SetPartDefault(thePlaneNumber);
199 CORBA::Boolean VISU::CutLines_i::IsDefaultPosition(CORBA::Long thePlaneNumber){
200 return myCutLinesPL->IsPartDefault(thePlaneNumber);
204 void VISU::CutLines_i::SetNbLines(CORBA::Long theNb) {
205 myCutLinesPL->SetNbParts(theNb);
207 CORBA::Long VISU::CutLines_i::GetNbLines() {
208 return myCutLinesPL->GetNbParts();
212 void VISU::CutLines_i::SetRotateX(CORBA::Double theAngle){
213 myCutLinesPL->SetRotateX(theAngle);
215 CORBA::Double VISU::CutLines_i::GetRotateX(){
216 return myCutLinesPL->GetRotateX();
219 void VISU::CutLines_i::SetRotateY(CORBA::Double theAngle){
220 myCutLinesPL->SetRotateY(theAngle);
222 CORBA::Double VISU::CutLines_i::GetRotateY(){
223 return myCutLinesPL->GetRotateY();
226 void VISU::CutLines_i::SetRotateX2(CORBA::Double theAngle){
227 myCutLinesPL->SetRotateX(theAngle,1);
229 CORBA::Double VISU::CutLines_i::GetRotateX2(){
230 return myCutLinesPL->GetRotateX(1);
233 void VISU::CutLines_i::SetRotateY2(CORBA::Double theAngle){
234 myCutLinesPL->SetRotateY(theAngle,1);
236 CORBA::Double VISU::CutLines_i::GetRotateY2(){
237 return myCutLinesPL->GetRotateY(1);
240 void VISU::CutLines_i::DoHook(){
241 if(!myPipeLine) myPipeLine = VISU_CutLinesPL::New();
242 myCutLinesPL = dynamic_cast<VISU_CutLinesPL*>(myPipeLine);
244 ScalarMap_i::DoHook();
247 void VISU::CutLines_i::BuildTableOfReal(SALOMEDS::SObject_ptr theSObject){
249 if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal");
251 SALOMEDS::GenericAttribute_var anAttr;
252 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
253 anAttr = aStudyBuilder->FindOrCreateAttribute(theSObject, "AttributeTableOfReal");
254 SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
256 typedef set<long> TLineCont;
257 typedef map<float,TLineCont> TXMap;
258 typedef map<float,float> TXYMap;
259 typedef vector<TXYMap> TCurveVect;
261 const VISU::TField::TValField& aValField = myField->myValField;
262 const VISU::TField::TValForTime& aValForTime = aValField.find((int)myIteration)->second;
263 const VISU::TField::TTime& aTime = aValForTime.myTime;
265 //aTitle.sprintf("%s %s",myTitle.c_str(),aTime.second.c_str());
266 aTitle.sprintf("%s",myTitle.c_str());
267 aTitle = aTitle.simplifyWhiteSpace();
268 aTableOfReal->SetTitle(aTitle.latin1());
270 int iLineEnd = myCutLinesPL->GetAppendPolyData()->GetNumberOfInputs();
271 if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal iLineEnd = "<<iLineEnd);
272 TCurveVect aCurveVect(iLineEnd);
275 const float *aDirLn = myCutLinesPL->GetDirLn();
276 const float *aBasePnt = myCutLinesPL->GetBasePnt();
277 const float *aBoundPrjLn = myCutLinesPL->GetBoundPrjLn();
278 for(int iLine = 0; iLine < iLineEnd; iLine++){
279 vtkDataSet *aDataSet = myCutLinesPL->GetAppendPolyData()->GetInput(iLine);
281 int aNbPoints = aDataSet->GetNumberOfPoints();
282 vtkPointData *aPointData = aDataSet->GetPointData();
283 vtkDataArray *aScalars = aPointData->GetScalars();
284 vtkCellDataToPointData *aFilter = NULL;
286 aFilter = vtkCellDataToPointData::New();
287 aFilter->SetInput(aDataSet);
288 aFilter->PassCellDataOn();
289 aDataSet = aFilter->GetOutput();
292 aPointData = aDataSet->GetPointData();
293 aScalars = aPointData->GetScalars();
294 if(!aScalars) continue;
295 if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal iLine = "<<iLine<<"; aNbPoints = "<<aNbPoints);
296 aLineCont.insert(iLine);
297 TXYMap& aXYMap = aCurveVect[iLine];
298 float aPnt[3], aVect[3], aDist;
299 for(int i = 0; i < aNbPoints; i++){
300 aDataSet->GetPoint(i,aPnt);
301 Sub(aPnt,aBasePnt,aVect);
302 aDist = vtkMath::Dot(aVect,aDirLn) / aBoundPrjLn[2];
304 if(aDist < 0.0) aDist = 0.0;
305 if(aDist > 1.0) aDist = 1.0;
306 aXYMap[aDist] = aScalars->GetTuple1(i);
307 //aXMap[aDist].insert(iLine);
309 if(aFilter) aFilter->Delete();
311 iLineEnd = aLineCont.size();
313 MESSAGE("CutPlanes_i::BuildTableOfReal aLineCont.size() == 0 !!!");
316 //Resorting of theXYMap
317 for(int iLine = 0; iLine < iLineEnd; iLine++){
318 TXYMap& aXYMap = aCurveVect[iLine], aNewXYMap;
319 if(aXYMap.size() > 2){
320 TXYMap::const_iterator aXYMapIter[2] = {aXYMap.begin(), ++aXYMap.begin()};
321 aNewXYMap[aXYMapIter[0]->first] = aXYMapIter[0]->second;
322 aXMap[aXYMapIter[0]->first].insert(iLine);
323 for(; aXYMapIter[1] != aXYMap.end(); aXYMapIter[0]++, aXYMapIter[1]++){
324 float aY[3] = {aXYMapIter[0]->second, aXYMapIter[1]->second, 0.0};
325 aY[2] = (aY[0] + aY[1])/2.0;
326 float aX[3] = {aXYMapIter[0]->first, aXYMapIter[1]->first, 0.0};
327 aX[2] = (aX[0] + aX[1])/2.0;
328 aNewXYMap[aX[2]] = aY[2];
329 aXMap[aX[2]].insert(iLine);
331 aNewXYMap[aXYMapIter[0]->first] = aXYMapIter[0]->second;
332 aXMap[aXYMapIter[0]->first].insert(iLine);
335 TXYMap::const_iterator aXYMapIter = aXYMap.begin();
336 for(; aXYMapIter != aXYMap.end(); aXYMapIter++){
337 aXMap[aXYMapIter->first].insert(iLine);
342 aTableOfReal->SetNbColumns(aXMap.size());
343 TXMap::const_iterator aXMapIter = aXMap.begin();
344 for(long i = 0; aXMapIter != aXMap.end(); aXMapIter++, i++){
345 float aDist = aXMapIter->first;
346 aTableOfReal->PutValue(aDist,1,i+1);
347 aString.sprintf("%d",i);
348 aTableOfReal->SetColumnTitle(i+1,aString.latin1());
349 const TLineCont& aLineCont = aXMapIter->second;
350 long jEnd = aLineCont.size();
351 if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal aDist = "<<aDist<<"; jEnd = "<<jEnd);
352 TLineCont::const_iterator aLineContIter = aLineCont.begin();
353 for(; aLineContIter != aLineCont.end(); aLineContIter++){
354 long iLine = *aLineContIter;
355 const TXYMap& aXYMap = aCurveVect[iLine];
356 TXYMap::const_iterator aXYMapIter = aXYMap.find(aDist);
357 if(aXYMapIter == aXYMap.end()) continue;
358 float aVal = aXYMapIter->second;
359 aTableOfReal->PutValue(aVal,iLine+2,i+1);
363 aTableOfReal->SetRowTitle(1,"X");
364 TLineCont::const_iterator aLineContIter = aLineCont.begin();
365 QString aUnitName = myField->myUnitNames[0].c_str();
366 int aScalarMode = myCutLinesPL->GetScalarMode();
368 aUnitName = myField->myUnitNames[aScalarMode-1].c_str();
369 aUnitName = aUnitName.simplifyWhiteSpace();
370 for(long i = 0; aLineContIter != aLineCont.end(); aLineContIter++, i++){
371 long iLine = *aLineContIter;
372 aString.sprintf("Y%d",iLine);
373 aTableOfReal->SetRowTitle(i+2,aString.latin1());
374 aTableOfReal->SetRowUnit(i+2,aUnitName.latin1());