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_ColoredPrs3d_i.hh"
29 #include "VISU_ScalarMapPL.hxx"
30 #include "VISU_Result_i.hh"
31 #include "VISU_Convertor.hxx"
33 #include "SUIT_ResourceMgr.h"
34 #include "SALOME_Event.hxx"
36 #include <vtkMapper.h>
42 static int MYDEBUG = 0;
45 static int MYDEBUG = 0;
49 //============================================================================
50 VISU::ColoredPrs3d_i::
51 ColoredPrs3d_i(Result_i* theResult,
53 PrsObject_i(theResult->GetStudyDocument()),
54 Prs3d_i(theResult,theAddToStudy),
59 VISU::ColoredPrs3d_i::
60 ColoredPrs3d_i(Result_i* theResult,
61 SALOMEDS::SObject_ptr theSObject) :
62 PrsObject_i(theResult->GetStudyDocument()),
63 Prs3d_i(theResult,theSObject),
72 //---------------------------------------------------------------
77 struct TRemoveFromStudy: public SALOME_Event
79 VISU::ColoredPrs3d_i* myRemovable;
80 TRemoveFromStudy(VISU::ColoredPrs3d_i* theRemovable):
81 myRemovable(theRemovable)
88 SALOMEDS::SObject_var aSObject = myRemovable->GetSObject();
89 if(!CORBA::is_nil(aSObject.in()))
90 VISU::RemoveFromStudy(aSObject,false);
91 myRemovable->TSuperClass::RemoveFromStudy();
95 ProcessVoidEvent(new TRemoveFromStudy(this));
98 //---------------------------------------------------------------
101 ::SameAs(const Prs3d_i* theOrigin)
103 if(const ColoredPrs3d_i* aPrs3d = dynamic_cast<const ColoredPrs3d_i*>(theOrigin)){
106 ColoredPrs3d_i* anOrigin = const_cast<ColoredPrs3d_i*>(aPrs3d);
108 myField = anOrigin->GetField();
109 myMeshName = myField->myMeshName;
110 myEntity = VISU::TEntity(anOrigin->GetEntity());//myField->myEntity;
111 myIteration = anOrigin->GetIteration();
112 myFieldName = anOrigin->GetFieldName();
116 TSuperClass::SameAs(theOrigin);
118 SetScalarMode(anOrigin->GetScalarMode());
119 SetNbColors(anOrigin->GetNbColors());
120 SetBarOrientation(anOrigin->GetBarOrientation());
122 SetPosition(anOrigin->GetPosX(), anOrigin->GetPosY());
123 SetSize(anOrigin->GetWidth(), anOrigin->GetHeight());
124 SetLabels(anOrigin->GetLabels());
125 SetTitle(anOrigin->GetTitle());
127 SetBoldTitle(anOrigin->IsBoldTitle());
128 SetItalicTitle(anOrigin->IsItalicTitle());
129 SetShadowTitle(anOrigin->IsShadowTitle());
130 SetTitFontType(anOrigin->GetTitFontType());
131 vtkFloatingPointType r,g,b;
132 anOrigin->GetTitleColor(&r,&g,&b);
133 SetTitleColor(r,g,b);
135 SetBoldLabel(anOrigin->IsBoldLabel());
136 SetItalicLabel(anOrigin->IsItalicLabel());
137 SetShadowLabel(anOrigin->IsShadowLabel());
138 SetLblFontType(anOrigin->GetLblFontType());
139 anOrigin->GetLabelColor(&r,&g,&b);
140 SetLabelColor(r,g,b);
146 ::SameAsParams(const ColoredPrs3d_i* theOrigin)
148 int anIteration = GetIteration();
150 myIteration = anIteration;
157 //----------------------------------------------------------------------------
162 return myScalarMapPL->GetScalarMode();
167 ::SetScalarMode(CORBA::Long theScalarMode)
169 myScalarMapPL->SetScalarMode(theScalarMode);
176 return myScalarMapPL->GetScalarRange()[0];
183 return myScalarMapPL->GetScalarRange()[1];
188 ::SetNbColors(CORBA::Long theNbColors)
190 myScalarMapPL->SetNbColors(theNbColors);
197 return myScalarMapPL->GetNbColors();
202 ::SetBarOrientation(VISU::ScalarMap::Orientation theOrientation)
204 myOrientation = theOrientation;
207 VISU::ScalarMap::Orientation
209 ::GetBarOrientation()
211 return myOrientation;
216 ::SetPosition(CORBA::Double X, CORBA::Double Y)
226 return myPosition[0];
233 return myPosition[1];
238 ::SetSize(CORBA::Double theWidth, CORBA::Double theHeight)
241 myHeight = theHeight;
260 ::SetLabels(CORBA::Long theNbLabels)
262 myNumberOfLabels = theNbLabels;
269 return myNumberOfLabels;
274 ::SetTitle(const char* theName)
283 return CORBA::string_dup(myTitle.c_str());
290 return myIsBoldTitle;
295 ::SetBoldTitle(bool isBold)
297 myIsBoldTitle = isBold;
304 return myIsItalicTitle;
309 ::SetItalicTitle(bool isItalic)
311 myIsItalicTitle = isItalic;
318 return myIsShadowTitle;
323 ::SetShadowTitle(bool isShadow)
325 myIsShadowTitle = isShadow;
332 return myTitFontType;
337 ::SetTitFontType(int theType)
339 myTitFontType = theType;
344 ::GetTitleColor(vtkFloatingPointType* theR,
345 vtkFloatingPointType* theG,
346 vtkFloatingPointType* theB)
348 *theR = myTitleColor[0];
349 *theG = myTitleColor[1];
350 *theB = myTitleColor[2];
355 ::SetTitleColor(vtkFloatingPointType theR,
356 vtkFloatingPointType theG,
357 vtkFloatingPointType theB)
359 myTitleColor[0] = theR;
360 myTitleColor[1] = theG;
361 myTitleColor[2] = theB;
368 return myIsBoldLabel;
373 ::SetBoldLabel(bool isBold)
375 myIsBoldLabel = isBold;
382 return myIsItalicLabel;
387 ::SetItalicLabel(bool isItalic)
389 myIsItalicLabel = isItalic;
396 return myIsShadowLabel;
401 ::SetShadowLabel(bool isShadow)
403 myIsShadowLabel = isShadow;
410 return myLblFontType;
415 ::SetLblFontType(int theType)
417 myLblFontType = theType;
422 ::GetLabelColor(vtkFloatingPointType* theR,
423 vtkFloatingPointType* theG,
424 vtkFloatingPointType* theB)
426 *theR = myLabelColor[0];
427 *theG = myLabelColor[1];
428 *theB = myLabelColor[2];
433 ::SetLabelColor(vtkFloatingPointType theR,
434 vtkFloatingPointType theG,
435 vtkFloatingPointType theB)
437 myLabelColor[0] = theR;
438 myLabelColor[1] = theG;
439 myLabelColor[2] = theB;
443 //----------------------------------------------------------------------------
445 * Creates ColoredPrs3d and initialises it from resources
449 ::Create(const char* theMeshName,
450 VISU::Entity theEntity,
451 const char* theFieldName,
454 DoHook(); // to create proper pipeline
456 myMeshName = theMeshName;
457 myEntity = (VISU::TEntity)theEntity;
458 myFieldName =theFieldName;
459 myIteration = theIteration;
461 Build(false); // to get corresponding input from result and initilize the pipeline
463 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
465 int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0);
466 SetScalarMode(aScalarMode);
468 int aNumberOfColors = aResourceMgr->integerValue( "VISU", "scalar_bar_num_colors", 64 );
469 SetNbColors(aNumberOfColors);
472 int anOrientation = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", 0);
473 if(anOrientation == 1)
474 myOrientation = VISU::ScalarMap::HORIZONTAL;
476 myOrientation = VISU::ScalarMap::VERTICAL;
479 QString propertyName = QString( "scalar_bar_%1_" ).arg( anOrientation == 0 ? "vertical" : "horizontal" );
481 vtkFloatingPointType aXorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.01 : 0.2;
482 aXorigin = aResourceMgr->doubleValue("VISU", propertyName + "x", aXorigin);
483 myPosition[0] = aXorigin;
485 vtkFloatingPointType aYorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.1 : 0.012;
486 aYorigin = aResourceMgr->doubleValue("VISU", propertyName + "y", aYorigin);
487 myPosition[1] = aYorigin;
490 myWidth = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.1 : 0.6;
491 myWidth = aResourceMgr->doubleValue("VISU", propertyName + "width", myWidth);
493 myHeight = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.8:0.12;
494 myHeight = aResourceMgr->doubleValue("VISU", propertyName + "height", myHeight);
496 // scalar bar default position
497 bool anIsArrangeBar = aResourceMgr->booleanValue("VISU", "scalar_bars_default_position", 0);
500 aPlace = aResourceMgr->integerValue("VISU", "scalar_bar_position_num",0);
502 if(myOrientation == VISU::ScalarMap::HORIZONTAL){
503 myPosition[1] += myHeight*(aPlace-1);
505 myPosition[0] += myWidth*(aPlace-1);
509 myNumberOfLabels = aResourceMgr->integerValue( "VISU", "scalar_bar_num_labels", 5 );
511 // Fonts properties definition
512 myIsBoldTitle = myIsItalicTitle = myIsShadowTitle = true;
513 myTitFontType = VTK_ARIAL;
515 if(aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" )){
516 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" );
517 if ( f.family() == "Arial" )
518 myTitFontType = VTK_ARIAL;
519 else if ( f.family() == "Courier" )
520 myTitFontType = VTK_COURIER;
521 else if ( f.family() == "Times" )
522 myTitFontType = VTK_TIMES;
524 myIsBoldTitle = f.bold();
525 myIsItalicTitle = f.italic();
526 myIsShadowTitle = f.underline();
529 QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
531 myTitleColor[0] = aTextColor.red() / 255;
532 myTitleColor[1] = aTextColor.green() / 255;
533 myTitleColor[2] = aTextColor.blue() / 255;
535 myIsBoldLabel = myIsItalicLabel = myIsShadowLabel = true;
536 myLblFontType = VTK_ARIAL;
538 if( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" )){
539 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" );
540 if ( f.family() == "Arial" )
541 myLblFontType = VTK_ARIAL;
542 else if ( f.family() == "Courier" )
543 myLblFontType = VTK_COURIER;
544 else if ( f.family() == "Times" )
545 myLblFontType = VTK_TIMES;
547 myIsBoldLabel = f.bold();
548 myIsItalicLabel = f.italic();
549 myIsShadowLabel = f.underline();
552 QColor aLabelColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
554 myLabelColor[0] = aLabelColor.red() / 255;
555 myLabelColor[1] = aLabelColor.green() / 255;
556 myLabelColor[2] = aLabelColor.blue() / 255;
563 ::Restore(const Storable::TRestoringMap& theMap)
567 myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1();
568 myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt();
569 myFieldName = VISU::Storable::FindValue(theMap,"myFieldName").latin1();
570 myIteration = VISU::Storable::FindValue(theMap,"myIteration").toInt();
572 myAddToStudy = false; //SRN Added 21/06/2003 SAL2983: to avoid addition of the new ScalarMap to study.
576 TSuperClass::Restore(theMap);
578 SetScalarMode(VISU::Storable::FindValue(theMap,"myScalarMode").toInt());
579 SetNbColors(VISU::Storable::FindValue(theMap,"myNumberOfColors").toInt());
580 SetBarOrientation((VISU::ScalarMap::Orientation)VISU::Storable::FindValue(theMap,"myOrientation").toInt());
582 myTitle = VISU::Storable::FindValue(theMap,"myTitle").latin1();
583 myNumberOfLabels = VISU::Storable::FindValue(theMap,"myNumberOfLabels").toInt();
584 myPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
585 myPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
586 myWidth = VISU::Storable::FindValue(theMap,"myWidth").toDouble();
587 myHeight = VISU::Storable::FindValue(theMap,"myHeight").toDouble();
589 myTitFontType = VISU::Storable::FindValue(theMap,"myTitFontType").toInt();
590 myIsBoldTitle = VISU::Storable::FindValue(theMap,"myIsBoldTitle").toInt();
591 myIsItalicTitle = VISU::Storable::FindValue(theMap,"myIsItalicTitle").toInt();
592 myIsShadowTitle = VISU::Storable::FindValue(theMap,"myIsShadowTitle").toInt();
593 myTitleColor[0] = VISU::Storable::FindValue(theMap,"myTitleColor[0]").toFloat();
594 myTitleColor[1] = VISU::Storable::FindValue(theMap,"myTitleColor[1]").toFloat();
595 myTitleColor[2] = VISU::Storable::FindValue(theMap,"myTitleColor[2]").toFloat();
597 myLblFontType = VISU::Storable::FindValue(theMap,"myLblFontType").toInt();
598 myIsBoldLabel = VISU::Storable::FindValue(theMap,"myIsBoldLabel").toInt();
599 myIsItalicLabel = VISU::Storable::FindValue(theMap,"myIsItalicLabel").toInt();
600 myIsShadowLabel = VISU::Storable::FindValue(theMap,"myIsShadowLabel").toInt();
601 myLabelColor[0] = VISU::Storable::FindValue(theMap,"myLabelColor[0]").toFloat();
602 myLabelColor[1] = VISU::Storable::FindValue(theMap,"myLabelColor[1]").toFloat();
603 myLabelColor[2] = VISU::Storable::FindValue(theMap,"myLabelColor[2]").toFloat();
610 ::ToStream(std::ostringstream& theStr)
612 TSuperClass::ToStream(theStr);
614 Storable::DataToStream( theStr, "myScalarMode", int(GetScalarMode()) );
615 Storable::DataToStream( theStr, "myNumberOfColors", int(GetNbColors()) );
616 Storable::DataToStream( theStr, "myOrientation", myOrientation );
618 Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() );
619 Storable::DataToStream( theStr, "myEntity", myEntity );
620 Storable::DataToStream( theStr, "myFieldName", myFieldName.c_str() );
621 Storable::DataToStream( theStr, "myIteration", myIteration );
623 Storable::DataToStream( theStr, "myTitle", myTitle.c_str() );
624 Storable::DataToStream( theStr, "myNumberOfLabels", myNumberOfLabels );
625 Storable::DataToStream( theStr, "myPosition[0]", myPosition[0] );
626 Storable::DataToStream( theStr, "myPosition[1]", myPosition[1] );
627 Storable::DataToStream( theStr, "myWidth", myWidth );
628 Storable::DataToStream( theStr, "myHeight", myHeight );
630 Storable::DataToStream( theStr, "myTitFontType", myTitFontType );
631 Storable::DataToStream( theStr, "myIsBoldTitle", myIsBoldTitle );
632 Storable::DataToStream( theStr, "myIsItalicTitle", myIsItalicTitle );
633 Storable::DataToStream( theStr, "myIsShadowTitle", myIsShadowTitle );
634 Storable::DataToStream( theStr, "myTitleColor[0]", myTitleColor[0] );
635 Storable::DataToStream( theStr, "myTitleColor[1]", myTitleColor[1] );
636 Storable::DataToStream( theStr, "myTitleColor[2]", myTitleColor[2] );
638 Storable::DataToStream( theStr, "myLblFontType", myLblFontType );
639 Storable::DataToStream( theStr, "myIsBoldLabel", myIsBoldLabel );
640 Storable::DataToStream( theStr, "myIsItalicLabel", myIsItalicLabel );
641 Storable::DataToStream( theStr, "myIsShadowLabel", myIsShadowLabel );
642 Storable::DataToStream( theStr, "myLabelColor[0]", myLabelColor[0] );
643 Storable::DataToStream( theStr, "myLabelColor[1]", myLabelColor[1] );
644 Storable::DataToStream( theStr, "myLabelColor[2]", myLabelColor[2] );
648 //----------------------------------------------------------------------------
653 if(MYDEBUG) MESSAGE("ColoredPrs3d_i::DoHook() - "<<myPipeLine);
655 myPipeLine = VISU_ScalarMapPL::New();
656 myPipeLine->GetMapper()->SetScalarVisibility(1);
658 myScalarMapPL = dynamic_cast<VISU_ScalarMapPL*>(myPipeLine);
661 //----------------------------------------------------------------------------
664 ::Build(int theRestoring)
667 MESSAGE("ColoredPrs3d_i::Build - "<<myFieldName<<"; theRestoring = "<<theRestoring);
668 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
670 aStudyBuilder->NewCommand(); // There is a transaction
674 DoSetInput(myResult);
677 if(theRestoring <= 0){
678 if(theRestoring == 0) myScalarMapPL->Init();
679 if(!myIsFixedRange) myScalarMapPL->SetSourceRange();
680 const VISU::TValField& aValField = myField->myValField;
681 const VISU::PValForTime aValForTime = aValField.find(myIteration)->second;
682 aComment.sprintf("%s %s",myFieldName.c_str(),VISU_Convertor::GenerateName(aValForTime->myTime).c_str());
683 if (theRestoring == 0) myTitle = aComment.simplifyWhiteSpace().latin1();
686 myName = GenerateName().latin1();
687 aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
688 VISU::TTIMESTAMP,myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp);
689 string aResultEntry = myResult->GetEntry();
690 string aRefFatherEntry = myResult->GetRefFatherEntry();
691 string anEntry = myResult->GetEntry(aComment.latin1());
692 if(anEntry == "") throw std::runtime_error("There is no Entry for binding the presentation !!!");
693 aComment.sprintf("myComment=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
694 GetComment(),myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp);
695 CORBA::String_var anIOR = GetID();
696 CreateAttributes(myStudy,anEntry.c_str(),aRefFatherEntry.c_str(),anIOR,myName.c_str(),"",aComment.latin1(),true);
697 mySObject = myStudy->FindObjectIOR(anIOR);
700 }catch(std::exception& exc){
701 INFOS("Follow exception was occured :\n"<<exc.what());
704 INFOS("Unknown exception was occured!");
709 aStudyBuilder->CommitCommand();
714 //----------------------------------------------------------------------------
724 ::GetMeshName() const
733 return VISU::Entity(myEntity);
738 ::GetFieldName() const
745 ::GetIteration() const
754 return myScalarMapPL;