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());
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(float* theR, float* theG, float* theB)
346 *theR = myTitleColor[0];
347 *theG = myTitleColor[1];
348 *theB = myTitleColor[2];
353 ::SetTitleColor(float theR, float theG, float theB)
355 myTitleColor[0] = theR;
356 myTitleColor[1] = theG;
357 myTitleColor[2] = theB;
364 return myIsBoldLabel;
369 ::SetBoldLabel(bool isBold)
371 myIsBoldLabel = isBold;
378 return myIsItalicLabel;
383 ::SetItalicLabel(bool isItalic)
385 myIsItalicLabel = isItalic;
392 return myIsShadowLabel;
397 ::SetShadowLabel(bool isShadow)
399 myIsShadowLabel = isShadow;
406 return myLblFontType;
411 ::SetLblFontType(int theType)
413 myLblFontType = theType;
418 ::GetLabelColor(float* theR, float* theG, float* theB)
420 *theR = myLabelColor[0];
421 *theG = myLabelColor[1];
422 *theB = myLabelColor[2];
427 ::SetLabelColor(float theR, float theG, float theB)
429 myLabelColor[0] = theR;
430 myLabelColor[1] = theG;
431 myLabelColor[2] = theB;
435 //----------------------------------------------------------------------------
437 * Creates ColoredPrs3d and initialises it from resources
441 ::Create(const char* theMeshName,
442 VISU::Entity theEntity,
443 const char* theFieldName,
446 DoHook(); // to create proper pipeline
448 myMeshName = theMeshName;
449 myEntity = (VISU::TEntity)theEntity;
450 myFieldName =theFieldName;
451 myIteration = theIteration;
453 Build(false); // to get corresponding input from result and initilize the pipeline
455 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
457 int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0);
458 SetScalarMode(aScalarMode);
460 int aNumberOfColors = aResourceMgr->integerValue( "VISU", "scalar_bar_num_colors", 64 );
461 SetNbColors(aNumberOfColors);
464 int anOrientation = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", 0);
465 if(anOrientation == 1)
466 myOrientation = VISU::ScalarMap::HORIZONTAL;
468 myOrientation = VISU::ScalarMap::VERTICAL;
471 QString propertyName = QString( "scalar_bar_%1_" ).arg( anOrientation == 0 ? "vertical" : "horizontal" );
473 float aXorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.01 : 0.2;
474 aXorigin = aResourceMgr->doubleValue("VISU", propertyName + "x", aXorigin);
475 myPosition[0] = aXorigin;
477 float aYorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.1 : 0.012;
478 aYorigin = aResourceMgr->doubleValue("VISU", propertyName + "y", aYorigin);
479 myPosition[1] = aYorigin;
482 myWidth = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.1 : 0.6;
483 myWidth = aResourceMgr->doubleValue("VISU", propertyName + "width", myWidth);
485 myHeight = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.8:0.12;
486 myHeight = aResourceMgr->doubleValue("VISU", propertyName + "height", myHeight);
488 // scalar bar default position
489 bool anIsArrangeBar = aResourceMgr->booleanValue("VISU", "scalar_bars_default_position", 0);
492 aPlace = aResourceMgr->integerValue("VISU", "scalar_bar_position_num",0);
494 if(myOrientation == VISU::ScalarMap::HORIZONTAL){
495 myPosition[1] += myHeight*(aPlace-1);
497 myPosition[0] += myWidth*(aPlace-1);
501 myNumberOfLabels = aResourceMgr->integerValue( "VISU", "scalar_bar_num_labels", 5 );
503 // Fonts properties definition
504 myIsBoldTitle = myIsItalicTitle = myIsShadowTitle = true;
505 myTitFontType = VTK_ARIAL;
507 if(aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" )){
508 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" );
509 if ( f.family() == "Arial" )
510 myTitFontType = VTK_ARIAL;
511 else if ( f.family() == "Courier" )
512 myTitFontType = VTK_COURIER;
513 else if ( f.family() == "Times" )
514 myTitFontType = VTK_TIMES;
516 myIsBoldTitle = f.bold();
517 myIsItalicTitle = f.italic();
518 myIsShadowTitle = f.underline();
521 QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
523 myTitleColor[0] = aTextColor.red() / 255;
524 myTitleColor[1] = aTextColor.green() / 255;
525 myTitleColor[2] = aTextColor.blue() / 255;
527 myIsBoldLabel = myIsItalicLabel = myIsShadowLabel = true;
528 myLblFontType = VTK_ARIAL;
530 if( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" )){
531 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" );
532 if ( f.family() == "Arial" )
533 myLblFontType = VTK_ARIAL;
534 else if ( f.family() == "Courier" )
535 myLblFontType = VTK_COURIER;
536 else if ( f.family() == "Times" )
537 myLblFontType = VTK_TIMES;
539 myIsBoldLabel = f.bold();
540 myIsItalicLabel = f.italic();
541 myIsShadowLabel = f.underline();
544 QColor aLabelColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
546 myLabelColor[0] = aLabelColor.red() / 255;
547 myLabelColor[1] = aLabelColor.green() / 255;
548 myLabelColor[2] = aLabelColor.blue() / 255;
555 ::Restore(const Storable::TRestoringMap& theMap)
559 myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1();
560 myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt();
561 myFieldName = VISU::Storable::FindValue(theMap,"myFieldName").latin1();
562 myIteration = VISU::Storable::FindValue(theMap,"myIteration").toInt();
564 myAddToStudy = false; //SRN Added 21/06/2003 SAL2983: to avoid addition of the new ScalarMap to study.
568 TSuperClass::Restore(theMap);
570 SetScalarMode(VISU::Storable::FindValue(theMap,"myScalarMode").toInt());
571 SetNbColors(VISU::Storable::FindValue(theMap,"myNumberOfColors").toInt());
572 SetBarOrientation((VISU::ScalarMap::Orientation)VISU::Storable::FindValue(theMap,"myOrientation").toInt());
574 myTitle = VISU::Storable::FindValue(theMap,"myTitle").latin1();
575 myNumberOfLabels = VISU::Storable::FindValue(theMap,"myNumberOfLabels").toInt();
576 myPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
577 myPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
578 myWidth = VISU::Storable::FindValue(theMap,"myWidth").toDouble();
579 myHeight = VISU::Storable::FindValue(theMap,"myHeight").toDouble();
581 myTitFontType = VISU::Storable::FindValue(theMap,"myTitFontType").toInt();
582 myIsBoldTitle = VISU::Storable::FindValue(theMap,"myIsBoldTitle").toInt();
583 myIsItalicTitle = VISU::Storable::FindValue(theMap,"myIsItalicTitle").toInt();
584 myIsShadowTitle = VISU::Storable::FindValue(theMap,"myIsShadowTitle").toInt();
585 myTitleColor[0] = VISU::Storable::FindValue(theMap,"myTitleColor[0]").toFloat();
586 myTitleColor[1] = VISU::Storable::FindValue(theMap,"myTitleColor[1]").toFloat();
587 myTitleColor[2] = VISU::Storable::FindValue(theMap,"myTitleColor[2]").toFloat();
589 myLblFontType = VISU::Storable::FindValue(theMap,"myLblFontType").toInt();
590 myIsBoldLabel = VISU::Storable::FindValue(theMap,"myIsBoldLabel").toInt();
591 myIsItalicLabel = VISU::Storable::FindValue(theMap,"myIsItalicLabel").toInt();
592 myIsShadowLabel = VISU::Storable::FindValue(theMap,"myIsShadowLabel").toInt();
593 myLabelColor[0] = VISU::Storable::FindValue(theMap,"myLabelColor[0]").toFloat();
594 myLabelColor[1] = VISU::Storable::FindValue(theMap,"myLabelColor[1]").toFloat();
595 myLabelColor[2] = VISU::Storable::FindValue(theMap,"myLabelColor[2]").toFloat();
602 ::ToStream(std::ostringstream& theStr)
604 TSuperClass::ToStream(theStr);
606 Storable::DataToStream( theStr, "myScalarMode", int(GetScalarMode()) );
607 Storable::DataToStream( theStr, "myNumberOfColors", int(GetNbColors()) );
608 Storable::DataToStream( theStr, "myOrientation", myOrientation );
610 Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() );
611 Storable::DataToStream( theStr, "myEntity", myEntity );
612 Storable::DataToStream( theStr, "myFieldName", myFieldName.c_str() );
613 Storable::DataToStream( theStr, "myIteration", myIteration );
615 Storable::DataToStream( theStr, "myTitle", myTitle.c_str() );
616 Storable::DataToStream( theStr, "myNumberOfLabels", myNumberOfLabels );
617 Storable::DataToStream( theStr, "myPosition[0]", myPosition[0] );
618 Storable::DataToStream( theStr, "myPosition[1]", myPosition[1] );
619 Storable::DataToStream( theStr, "myWidth", myWidth );
620 Storable::DataToStream( theStr, "myHeight", myHeight );
622 Storable::DataToStream( theStr, "myTitFontType", myTitFontType );
623 Storable::DataToStream( theStr, "myIsBoldTitle", myIsBoldTitle );
624 Storable::DataToStream( theStr, "myIsItalicTitle", myIsItalicTitle );
625 Storable::DataToStream( theStr, "myIsShadowTitle", myIsShadowTitle );
626 Storable::DataToStream( theStr, "myTitleColor[0]", myTitleColor[0] );
627 Storable::DataToStream( theStr, "myTitleColor[1]", myTitleColor[1] );
628 Storable::DataToStream( theStr, "myTitleColor[2]", myTitleColor[2] );
630 Storable::DataToStream( theStr, "myLblFontType", myLblFontType );
631 Storable::DataToStream( theStr, "myIsBoldLabel", myIsBoldLabel );
632 Storable::DataToStream( theStr, "myIsItalicLabel", myIsItalicLabel );
633 Storable::DataToStream( theStr, "myIsShadowLabel", myIsShadowLabel );
634 Storable::DataToStream( theStr, "myLabelColor[0]", myLabelColor[0] );
635 Storable::DataToStream( theStr, "myLabelColor[1]", myLabelColor[1] );
636 Storable::DataToStream( theStr, "myLabelColor[2]", myLabelColor[2] );
640 //----------------------------------------------------------------------------
645 if(MYDEBUG) MESSAGE("ColoredPrs3d_i::DoHook() - "<<myPipeLine);
647 myPipeLine = VISU_ScalarMapPL::New();
648 myPipeLine->GetMapper()->SetScalarVisibility(1);
650 myScalarMapPL = dynamic_cast<VISU_ScalarMapPL*>(myPipeLine);
653 //----------------------------------------------------------------------------
656 ::Build(int theRestoring)
659 MESSAGE("ColoredPrs3d_i::Build - "<<myFieldName<<"; theRestoring = "<<theRestoring);
660 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
662 aStudyBuilder->NewCommand(); // There is a transaction
666 DoSetInput(myResult);
669 if(theRestoring <= 0){
670 if(theRestoring == 0) myScalarMapPL->Init();
671 if(!myIsFixedRange) myScalarMapPL->SetSourceRange();
672 const VISU::TValField& aValField = myField->myValField;
673 const VISU::PValForTime aValForTime = aValField.find(myIteration)->second;
674 aComment.sprintf("%s %s",myFieldName.c_str(),VISU_Convertor::GenerateName(aValForTime->myTime).c_str());
675 if (theRestoring == 0) myTitle = aComment.simplifyWhiteSpace().latin1();
678 myName = GenerateName().latin1();
679 aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
680 VISU::TTIMESTAMP,myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp);
681 string aResultEntry = myResult->GetEntry();
682 string aRefFatherEntry = myResult->GetRefFatherEntry();
683 string anEntry = myResult->GetEntry(aComment.latin1());
684 if(anEntry == "") throw std::runtime_error("There is no Entry for binding the presentation !!!");
685 aComment.sprintf("myComment=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
686 GetComment(),myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp);
687 CORBA::String_var anIOR = GetID();
688 CreateAttributes(myStudy,anEntry.c_str(),aRefFatherEntry.c_str(),anIOR,myName.c_str(),"",aComment.latin1(),true);
689 mySObject = myStudy->FindObjectIOR(anIOR);
692 }catch(std::exception& exc){
693 INFOS("Follow exception was occured :\n"<<exc.what());
696 INFOS("Unknown exception was occured!");
701 aStudyBuilder->CommitCommand();
706 //----------------------------------------------------------------------------
716 ::GetMeshName() const
725 return VISU::Entity(myEntity);
730 ::GetFieldName() const
737 ::GetIteration() const
746 return myScalarMapPL;