From: admin Date: Mon, 29 Aug 2005 08:09:13 +0000 (+0000) Subject: This commit was generated by cvs2git to create branch 'BR-D5-38-2003'. X-Git-Tag: BR-D5-38-2003_D2005-12-09~87 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7104281b4d4e11079285d9f8c358477e6b1f66db;p=modules%2Fvisu.git This commit was generated by cvs2git to create branch 'BR-D5-38-2003'. Cherrypick from master 2005-08-29 08:09:12 UTC apo 'To customize ScalarMap descendants': src/VISU_I/VISU_CutLines_i.cc src/VISU_I/VISU_ScalarMap_i.cc src/VISU_I/VISU_ScalarMap_i.hh --- diff --git a/src/VISU_I/VISU_CutLines_i.cc b/src/VISU_I/VISU_CutLines_i.cc new file mode 100644 index 00000000..d542b221 --- /dev/null +++ b/src/VISU_I/VISU_CutLines_i.cc @@ -0,0 +1,396 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISU_PrsObject_i.cxx +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_CutLinesPL.hxx" +#include "VISU_Result_i.hh" +#include "VISU_CutLines_i.hh" +#include "VISU_Actor.h" + +#include "VISU_PipeLineUtils.hxx" + +#include + +using namespace VISU; +using namespace std; + +static float EPS_machine = 1.0E-7; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +int VISU::CutLines_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration, int isMemoryCheck) +{ + return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,isMemoryCheck); +} + +int VISU::CutLines_i::myNbPresent = 0; +QString VISU::CutLines_i::GenerateName() { return VISU::GenerateName("CutLines",myNbPresent++);} + +const string VISU::CutLines_i::myComment = "CUTLINES"; +const char* VISU::CutLines_i::GetComment() const { return myComment.c_str();} + + +VISU::CutLines_i:: +CutLines_i(Result_i* theResult, + bool theAddToStudy) : + PrsObject_i(theResult->GetStudyDocument()), + Prs3d_i(theResult,theAddToStudy), + ScalarMap_i(theResult,theAddToStudy), + myCutLinesPL(NULL) +{ +} + + +VISU::CutLines_i:: +CutLines_i(Result_i* theResult, + SALOMEDS::SObject_ptr theSObject) : + PrsObject_i(theResult->GetStudyDocument()), + Prs3d_i(theResult,theSObject), + ScalarMap_i(theResult,theSObject), + myCutLinesPL(NULL) +{ +} + + +void VISU::CutLines_i::SameAs(const CutLines_i* theOrigin){ + VISU::ScalarMap_i::SameAs(theOrigin); +} + + +VISU::Storable* VISU::CutLines_i::Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration); +} + + +VISU::Storable* VISU::CutLines_i::Restore(const Storable::TRestoringMap& theMap) +{ + DoHook(); + SetNbLines(VISU::Storable::FindValue(theMap,"myNbLines").toInt()); + SetDisplacement(VISU::Storable::FindValue(theMap,"myDisplacement[0]").toDouble()); + SetDisplacement2(VISU::Storable::FindValue(theMap,"myDisplacement[1]").toDouble()); + SetOrientation(CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[0]").toInt()), + Storable::FindValue(theMap,"aRot[0][0]").toDouble(), + Storable::FindValue(theMap,"aRot[0][1]").toDouble()); + SetOrientation2(CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[1]").toInt()), + Storable::FindValue(theMap,"aRot[1][0]").toDouble(), + Storable::FindValue(theMap,"aRot[1][1]").toDouble()); + if (VISU::Storable::FindValue(theMap,"myBasePlaneCondition").toInt()) + SetDefault(); + else + SetBasePlanePosition(VISU::Storable::FindValue(theMap,"myBasePlanePosition").toDouble()); + + QStringList aPosList = QStringList::split("|",VISU::Storable::FindValue(theMap,"myLinePosition") ); + QStringList aCondList = QStringList::split("|",VISU::Storable::FindValue(theMap,"myLineCondition") ); + for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++) + if(aCondList[i].toInt() == 0) + SetLinePosition(i,aPosList[i].toDouble()); + + return ScalarMap_i::Restore(theMap); +} + + +void VISU::CutLines_i::ToStream(std::ostringstream& theStr){ + ScalarMap_i::ToStream(theStr); + + int aNbLines = GetNbLines(); + + Storable::DataToStream( theStr, "myNbLines", aNbLines ); + Storable::DataToStream( theStr, "myDisplacement[0]", GetDisplacement() ); + Storable::DataToStream( theStr, "myDisplacement[1]", GetDisplacement2() ); + Storable::DataToStream( theStr, "myBasePlane[0]", int(GetOrientationType()) ); + Storable::DataToStream( theStr, "myBasePlane[1]", int(GetOrientationType2()) ); + Storable::DataToStream( theStr, "aRot[0][0]", GetRotateX() ); + Storable::DataToStream( theStr, "aRot[0][1]", GetRotateY() ); + Storable::DataToStream( theStr, "aRot[1][0]", GetRotateX2() ); + Storable::DataToStream( theStr, "aRot[1][1]", GetRotateY2() ); + Storable::DataToStream( theStr, "myBasePlanePosition", GetBasePlanePosition() ); + Storable::DataToStream( theStr, "myBasePlaneCondition", IsDefault() ); + + QString aStrPos, aStrCon; + for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++){ + aStrPos.append(QString::number(GetLinePosition(i)) + "|"); + aStrCon.append(QString::number(IsDefaultPosition(i)) + "|"); + } + Storable::DataToStream( theStr, "myLinePosition", aStrPos.latin1()); + Storable::DataToStream( theStr, "myLineCondition", aStrCon.latin1()); +} + +VISU::CutLines_i::~CutLines_i(){ + if(MYDEBUG) MESSAGE("CutLines_i::~CutLines_i()"); +} + + +void VISU::CutLines_i::SetOrientation(VISU::CutPlanes::Orientation theOrient, + CORBA::Double theXAngle, CORBA::Double theYAngle) +{ + myCutLinesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(theOrient), + theXAngle,theYAngle); +} +void VISU::CutLines_i::SetOrientation2(VISU::CutPlanes::Orientation theOrient, + CORBA::Double theXAngle, CORBA::Double theYAngle) +{ + myCutLinesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(theOrient), + theXAngle,theYAngle,1); +} + +VISU::CutPlanes::Orientation VISU::CutLines_i::GetOrientationType() { + return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation()); +} +VISU::CutPlanes::Orientation VISU::CutLines_i::GetOrientationType2() { + return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation(1)); +} + +CORBA::Double VISU::CutLines_i::GetRotateX(){ + return myCutLinesPL->GetRotateX(); +} +CORBA::Double VISU::CutLines_i::GetRotateY(){ + return myCutLinesPL->GetRotateY(); +} + +CORBA::Double VISU::CutLines_i::GetRotateX2(){ + return myCutLinesPL->GetRotateX(1); +} +CORBA::Double VISU::CutLines_i::GetRotateY2(){ + return myCutLinesPL->GetRotateY(1); +} + + +void VISU::CutLines_i::SetDisplacement(CORBA::Double theDisp) { + myCutLinesPL->SetDisplacement(theDisp); +} +void VISU::CutLines_i::SetDisplacement2(CORBA::Double theDisp) { + myCutLinesPL->SetDisplacement(theDisp,1); +} + +CORBA::Double VISU::CutLines_i::GetDisplacement() { + return myCutLinesPL->GetDisplacement(); +} +CORBA::Double VISU::CutLines_i::GetDisplacement2() { + return myCutLinesPL->GetDisplacement(1); +} + + +void VISU::CutLines_i::SetBasePlanePosition(CORBA::Double thePlanePosition){ + myCutLinesPL->SetPosition(thePlanePosition); +} + +CORBA::Double VISU::CutLines_i::GetBasePlanePosition(){ + return myCutLinesPL->GetPosition(); +} + +void VISU::CutLines_i::SetLinePosition(CORBA::Long thePlaneNumber, CORBA::Double thePlanePosition){ + myCutLinesPL->SetPartPosition(thePlaneNumber,thePlanePosition); +} + +CORBA::Double VISU::CutLines_i::GetLinePosition(CORBA::Long thePlaneNumber){ + return myCutLinesPL->GetPartPosition(thePlaneNumber,1); +} + + +void VISU::CutLines_i::SetDefault(){ + myCutLinesPL->SetDefault(); +} + +CORBA::Boolean VISU::CutLines_i::IsDefault(){ + return myCutLinesPL->IsDefault(); +} + +void VISU::CutLines_i::SetDefaultPosition(CORBA::Long thePlaneNumber){ + myCutLinesPL->SetPartDefault(thePlaneNumber); +} + +CORBA::Boolean VISU::CutLines_i::IsDefaultPosition(CORBA::Long thePlaneNumber){ + return myCutLinesPL->IsPartDefault(thePlaneNumber); +} + + +void VISU::CutLines_i::SetNbLines(CORBA::Long theNb) { + myCutLinesPL->SetNbParts(theNb); +} +CORBA::Long VISU::CutLines_i::GetNbLines() { + return myCutLinesPL->GetNbParts(); +} + + +void VISU::CutLines_i::DoHook(){ + if(!myPipeLine) myPipeLine = VISU_CutLinesPL::New(); + myCutLinesPL = dynamic_cast(myPipeLine); + + ScalarMap_i::DoHook(); +} + +void VISU::CutLines_i::BuildTableOfReal(SALOMEDS::SObject_ptr theSObject){ + try{ + if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal"); + Update(); + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder(); + anAttr = aStudyBuilder->FindOrCreateAttribute(theSObject, "AttributeTableOfReal"); + SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr); + + typedef set TXCont; + typedef map TXYMap; + typedef map TXYMapCont; + typedef map TLineIdCont; + + QString aTitle; + aTitle.sprintf("%s",myTitle.c_str()); + aTitle = aTitle.simplifyWhiteSpace(); + aTableOfReal->SetTitle(aTitle.latin1()); + + int iLineEnd = myCutLinesPL->GetAppendPolyData()->GetNumberOfInputs(); + if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal iLineEnd = "<GetDirLn(); + const float *aBasePnt = myCutLinesPL->GetBasePnt(); + const float *aBoundPrjLn = myCutLinesPL->GetBoundPrjLn(); + for(int iLine = 0, jLine = 0; iLine < iLineEnd; iLine++){ + vtkDataSet *aDataSet = myCutLinesPL->GetAppendPolyData()->GetInput(iLine); + aDataSet->Update(); + int aNbPoints = aDataSet->GetNumberOfPoints(); + if(!aNbPoints) continue; + vtkPointData *aPointData = aDataSet->GetPointData(); + vtkDataArray *aScalars = aPointData->GetScalars(); + vtkCellDataToPointData *aFilter = NULL; + if(!aScalars) { + aFilter = vtkCellDataToPointData::New(); + aFilter->SetInput(aDataSet); + aFilter->PassCellDataOn(); + aDataSet = aFilter->GetOutput(); + aDataSet->Update(); + } + aPointData = aDataSet->GetPointData(); + aScalars = aPointData->GetScalars(); + if(!aScalars) continue; + if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal iLine = "<second, aNewXYMap; + if(aXYMap.size() > 2){ + // Try to smooth the values of the line by applying linear approximation + TXYMap::const_iterator aXYMapIter[2] = {aXYMap.begin(), ++aXYMap.begin()}; + aNewXYMap[aXYMapIter[0]->first] = aXYMapIter[0]->second; + aXCont.insert(aXYMapIter[0]->first); + for(; aXYMapIter[1] != aXYMap.end(); aXYMapIter[0]++, aXYMapIter[1]++){ + float aY[3] = {aXYMapIter[0]->second, aXYMapIter[1]->second, 0.0}; + aY[2] = (aY[0] + aY[1])/2.0; + float aX[3] = {aXYMapIter[0]->first, aXYMapIter[1]->first, 0.0}; + aX[2] = (aX[0] + aX[1])/2.0; + aNewXYMap[aX[2]] = aY[2]; + aXCont.insert(aX[2]); + } + aNewXYMap[aXYMapIter[0]->first] = aXYMapIter[0]->second; + aXCont.insert(aXYMapIter[0]->first); + aXYMap = aNewXYMap; + }else{ + TXYMap::const_iterator aXYMapIter = aXYMap.begin(); + for(; aXYMapIter != aXYMap.end(); aXYMapIter++) + aXCont.insert(aXYMapIter->first); + } + } + if(aXCont.size() == 0) + throw std::runtime_error("CutPlanes_i::BuildTableOfReal aXCont.size() == 0 !!!"); + QString aString; + int iEnd = aXCont.size(); + aTableOfReal->SetNbColumns(iEnd); + TXCont::const_iterator aXContIter = aXCont.begin(); + for(long i = 0; aXContIter != aXCont.end(); aXContIter++, i++){ + float aDist = *aXContIter; + aTableOfReal->PutValue(aDist,1,i+1); + aString.sprintf("%d",i); + aTableOfReal->SetColumnTitle(i+1,aString.latin1()); + if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal aDist = "<first; + long iLineId = aLineIdCont[iLine]; + const TXYMap& aXYMap = aXYMapCont[iLine]; + TXYMap::const_iterator aXYMapIter = aXYMap.find(aDist); + // Can we find some value that belong to the line and have the same X coordinate? + if(aXYMapIter == aXYMap.end()) continue; + float aVal = aXYMapIter->second; + aTableOfReal->PutValue(aVal,iLineId+2,i+1); + } + } + { + aTableOfReal->SetRowTitle(1,"X"); + aTableOfReal->SetRowUnit(1,"-"); + QString aUnitName = myField->myUnitNames[0].c_str(); + int aScalarMode = myCutLinesPL->GetScalarMode(); + if(aScalarMode != 0) + aUnitName = myField->myUnitNames[aScalarMode-1].c_str(); + aUnitName = aUnitName.simplifyWhiteSpace(); + if(aUnitName.isEmpty()) aUnitName = "-"; + TXYMapCont::const_iterator aXYMapContIter = aXYMapCont.begin(); + for(; aXYMapContIter != aXYMapCont.end(); aXYMapContIter++){ + long iLine = aXYMapContIter->first; + long iLineId = aLineIdCont[iLine]; + aString.sprintf("Y%d",iLine); + if(MYDEBUG) + MESSAGE("CutPlanes_i::BuildTableOfReal - SetRowTitle("<SetRowTitle(iLineId+2,aString.latin1()); + aTableOfReal->SetRowUnit(iLineId+2,aUnitName.latin1()); + } + } + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"< +#include + +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +static int INCMEMORY = 4; + +int VISU::ScalarMap_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration, int isMemoryCheck) +{ + try{ + float aSize = INCMEMORY* + theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration); + bool aResult = true; + if(isMemoryCheck){ + aResult = VISU_PipeLine::CheckAvailableMemory(aSize); + MESSAGE("ScalarMap_i::IsPossible - CheckAvailableMemory = "<GetStudyDocument()), + Prs3d_i(theResult,theAddToStudy), + myScalarMapPL(NULL) +{ +} + + +VISU::ScalarMap_i:: +ScalarMap_i(Result_i* theResult, + SALOMEDS::SObject_ptr theSObject) : + PrsObject_i(theResult->GetStudyDocument()), + Prs3d_i(theResult,theSObject), + myScalarMapPL(NULL) +{ +} + + +void VISU::ScalarMap_i::RemoveFromStudy() +{ + VISU::DeleteActors(this); + VISU::RemoveFromStudy(mySObject,false); +} + + +void VISU::ScalarMap_i::SameAs(const ScalarMap_i* theOrigin) +{ + ScalarMap_i* aScalarMap = const_cast(theOrigin); + DoHook(); + VISU::Prs3d_i::SameAs(aScalarMap); + myField = aScalarMap->GetField(); + myMeshName = myField->myMeshName; + myEntity = myField->myEntity; + myIteration = aScalarMap->GetIteration(); + myFieldName = aScalarMap->GetFieldName(); + + SetScalarMode(aScalarMap->GetScalarMode()); + + SetRange(aScalarMap->GetMin(), aScalarMap->GetMax()); + myIsFixedRange = aScalarMap->IsRangeFixed(); + + SetScaling(aScalarMap->GetScaling()); + + SetBarOrientation(aScalarMap->GetBarOrientation()); + SetPosition(aScalarMap->GetPosX(), aScalarMap->GetPosY()); + SetSize(aScalarMap->GetWidth(), aScalarMap->GetHeight()); + SetNbColors(aScalarMap->GetNbColors()); + SetLabels(aScalarMap->GetLabels()); + SetTitle(aScalarMap->GetTitle()); + + SetBoldTitle(aScalarMap->IsBoldTitle()); + SetItalicTitle(aScalarMap->IsItalicTitle()); + SetShadowTitle(aScalarMap->IsShadowTitle()); + SetTitFontType(aScalarMap->GetTitFontType()); + float r,g,b; + aScalarMap->GetTitleColor(&r,&g,&b); + SetTitleColor(r,g,b); + + SetBoldLabel(aScalarMap->IsBoldLabel()); + SetItalicLabel(aScalarMap->IsItalicLabel()); + SetShadowLabel(aScalarMap->IsShadowLabel()); + SetLblFontType(aScalarMap->GetLblFontType()); + aScalarMap->GetLabelColor(&r,&g,&b); + SetLabelColor(r,g,b); + + Build(-1); + Update(); +} + +void VISU::ScalarMap_i::SameAsParams (const ScalarMap_i* theOrigin) +{ + int time = GetIteration(); + SameAs(theOrigin); + myIteration = time; + + //??Build(true); + Build(-1); + Update(); +} + + +/** + * Creates Scalar Map and initialises it from resources + */ +VISU::Storable* VISU::ScalarMap_i::Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + DoHook(); + + SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); + + int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0); + SetScalarMode(aScalarMode); + + // Orientation + int orient = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", 0); + if (orient == 1) + myOrientation = VISU::ScalarMap::HORIZONTAL; + else + myOrientation = VISU::ScalarMap::VERTICAL; + + // Scalar Bar origin + QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" ); + + float aXorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.01 : 0.2; + aXorigin = aResourceMgr->doubleValue("VISU", propertyName + "x", aXorigin); + myPosition[0] = aXorigin; + + float aYorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.1 : 0.012; + aYorigin = aResourceMgr->doubleValue("VISU", propertyName + "y", aYorigin); + myPosition[1] = aYorigin; + + // Scalar Bar size + myWidth = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.1 : 0.6; + myWidth = aResourceMgr->doubleValue("VISU", propertyName + "width", myWidth); + + myHeight = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.8:0.12; + myHeight = aResourceMgr->doubleValue("VISU", propertyName + "height", myHeight); + + // Nb of Colors + int aNumberOfColors = aResourceMgr->integerValue( "VISU", "scalar_bar_num_colors", 64 ); + SetNbColors(aNumberOfColors); + + // Nb of Labels + myNumberOfLabels = aResourceMgr->integerValue( "VISU", "scalar_bar_num_labels", 5 ); + + // Scalar Range + int rangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0); + myIsFixedRange = (rangeType == 1) ? true : false; + + if (myIsFixedRange) + { + float aMin = aResourceMgr->doubleValue("VISU", "scalar_range_min", 0); + float aMax = aResourceMgr->doubleValue("VISU", "scalar_range_max", 0); + SetRange(aMin,aMax); + } + + bool isLog = aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false); + + if( isLog ) + SetScaling(VISU::LOGARITHMIC); + else + SetScaling(VISU::LINEAR); + + // Fonts properties definition + myIsBoldTitle = myIsItalicTitle = myIsShadowTitle = true; + myTitFontType = VTK_ARIAL; + + if ( aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" ) ) + { + QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" ); + + if ( f.family() == "Arial" ) + myTitFontType = VTK_ARIAL; + else if ( f.family() == "Courier" ) + myTitFontType = VTK_COURIER; + else if ( f.family() == "Times" ) + myTitFontType = VTK_TIMES; + + myIsBoldTitle = f.bold(); + myIsItalicTitle = f.italic(); + myIsShadowTitle = f.underline(); + } + + QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) ); + + myTitleColor[0] = aTextColor.red() / 255; + myTitleColor[1] = aTextColor.green() / 255; + myTitleColor[2] = aTextColor.blue() / 255; + + /// + + myIsBoldLabel = myIsItalicLabel = myIsShadowLabel = true; + myLblFontType = VTK_ARIAL; + + if ( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" ) ) + { + QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" ); + + if ( f.family() == "Arial" ) + myLblFontType = VTK_ARIAL; + else if ( f.family() == "Courier" ) + myLblFontType = VTK_COURIER; + else if ( f.family() == "Times" ) + myLblFontType = VTK_TIMES; + + myIsBoldLabel = f.bold(); + myIsItalicLabel = f.italic(); + myIsShadowLabel = f.underline(); + } + + QColor aLabelColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) ); + + myLabelColor[0] = aLabelColor.red() / 255; + myLabelColor[1] = aLabelColor.green() / 255; + myLabelColor[2] = aLabelColor.blue() / 255; + + + myMeshName = theMeshName; + myEntity = (VISU::TEntity)theEntity; + myFieldName =theFieldName; + myIteration = theIteration; + + return Build(false); +} + + +VISU::Storable* VISU::ScalarMap_i::Restore(const Storable::TRestoringMap& theMap) +{ + DoHook(); + myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1(); + myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt(); + myFieldName = VISU::Storable::FindValue(theMap,"myFieldName").latin1(); + myIteration = VISU::Storable::FindValue(theMap,"myIteration").toInt(); + + SetScalarMode(VISU::Storable::FindValue(theMap,"myScalarMode").toInt()); + SetScaling(VISU::Scaling(VISU::Storable::FindValue(theMap,"myScaling").toInt())); + float aMin = VISU::Storable::FindValue(theMap,"myScalarRange[0]").toDouble(); + float aMax = VISU::Storable::FindValue(theMap,"myScalarRange[1]").toDouble(); + SetRange(aMin,aMax); + myIsFixedRange = VISU::Storable::FindValue(theMap,"myIsFixedRange").toInt(); + + myTitle = VISU::Storable::FindValue(theMap,"myTitle").latin1(); + myOrientation = (VISU::ScalarMap::Orientation)VISU::Storable::FindValue(theMap,"myOrientation").toInt(); + SetNbColors(VISU::Storable::FindValue(theMap,"myNumberOfColors").toInt()); + myNumberOfLabels = VISU::Storable::FindValue(theMap,"myNumberOfLabels").toInt(); + myPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble(); + myPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble(); + myWidth = VISU::Storable::FindValue(theMap,"myWidth").toDouble(); + myHeight = VISU::Storable::FindValue(theMap,"myHeight").toDouble(); + + myTitFontType = VISU::Storable::FindValue(theMap,"myTitFontType").toInt(); + myIsBoldTitle = VISU::Storable::FindValue(theMap,"myIsBoldTitle").toInt(); + myIsItalicTitle = VISU::Storable::FindValue(theMap,"myIsItalicTitle").toInt(); + myIsShadowTitle = VISU::Storable::FindValue(theMap,"myIsShadowTitle").toInt(); + myTitleColor[0] = VISU::Storable::FindValue(theMap,"myTitleColor[0]").toFloat(); + myTitleColor[1] = VISU::Storable::FindValue(theMap,"myTitleColor[1]").toFloat(); + myTitleColor[2] = VISU::Storable::FindValue(theMap,"myTitleColor[2]").toFloat(); + + myLblFontType = VISU::Storable::FindValue(theMap,"myLblFontType").toInt(); + myIsBoldLabel = VISU::Storable::FindValue(theMap,"myIsBoldLabel").toInt(); + myIsItalicLabel = VISU::Storable::FindValue(theMap,"myIsItalicLabel").toInt(); + myIsShadowLabel = VISU::Storable::FindValue(theMap,"myIsShadowLabel").toInt(); + myLabelColor[0] = VISU::Storable::FindValue(theMap,"myLabelColor[0]").toFloat(); + myLabelColor[1] = VISU::Storable::FindValue(theMap,"myLabelColor[1]").toFloat(); + myLabelColor[2] = VISU::Storable::FindValue(theMap,"myLabelColor[2]").toFloat(); + + Prs3d_i::Restore(theMap); + myAddToStudy = false; //SRN Added 21/06/2003 SAL2983: to avoid addition of the new ScalarMap to study. + return Build(true); +} + + +void VISU::ScalarMap_i::ToStream(std::ostringstream& theStr){ + Prs3d_i::ToStream(theStr); + + Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() ); + Storable::DataToStream( theStr, "myEntity", myEntity ); + Storable::DataToStream( theStr, "myFieldName", myFieldName.c_str() ); + Storable::DataToStream( theStr, "myIteration", myIteration ); + + Storable::DataToStream( theStr, "myScalarMode", int(GetScalarMode()) ); + Storable::DataToStream( theStr, "myScalarRange[0]", GetMin() ); + Storable::DataToStream( theStr, "myScalarRange[1]", GetMax() ); + Storable::DataToStream( theStr, "myIsFixedRange", myIsFixedRange ); + Storable::DataToStream( theStr, "myScaling", GetScaling() ); + + Storable::DataToStream( theStr, "myTitle", myTitle.c_str() ); + Storable::DataToStream( theStr, "myOrientation", myOrientation ); + Storable::DataToStream( theStr, "myNumberOfColors", int(GetNbColors()) ); + Storable::DataToStream( theStr, "myNumberOfLabels", myNumberOfLabels ); + Storable::DataToStream( theStr, "myPosition[0]", myPosition[0] ); + Storable::DataToStream( theStr, "myPosition[1]", myPosition[1] ); + Storable::DataToStream( theStr, "myWidth", myWidth ); + Storable::DataToStream( theStr, "myHeight", myHeight ); + + Storable::DataToStream( theStr, "myTitFontType", myTitFontType ); + Storable::DataToStream( theStr, "myIsBoldTitle", myIsBoldTitle ); + Storable::DataToStream( theStr, "myIsItalicTitle", myIsItalicTitle ); + Storable::DataToStream( theStr, "myIsShadowTitle", myIsShadowTitle ); + Storable::DataToStream( theStr, "myTitleColor[0]", myTitleColor[0] ); + Storable::DataToStream( theStr, "myTitleColor[1]", myTitleColor[1] ); + Storable::DataToStream( theStr, "myTitleColor[2]", myTitleColor[2] ); + + Storable::DataToStream( theStr, "myLblFontType", myLblFontType ); + Storable::DataToStream( theStr, "myIsBoldLabel", myIsBoldLabel ); + Storable::DataToStream( theStr, "myIsItalicLabel", myIsItalicLabel ); + Storable::DataToStream( theStr, "myIsShadowLabel", myIsShadowLabel ); + Storable::DataToStream( theStr, "myLabelColor[0]", myLabelColor[0] ); + Storable::DataToStream( theStr, "myLabelColor[1]", myLabelColor[1] ); + Storable::DataToStream( theStr, "myLabelColor[2]", myLabelColor[2] ); +} + + +CORBA::Long VISU::ScalarMap_i::GetScalarMode(){ + return myScalarMapPL->GetScalarMode(); +} +void VISU::ScalarMap_i::SetScalarMode(CORBA::Long theScalarMode) { + myScalarMapPL->SetScalarMode(theScalarMode); +} + + +VISU::Scaling VISU::ScalarMap_i::GetScaling(){ + return VISU::Scaling(myScalarMapPL->GetScaling()); +} +void VISU::ScalarMap_i::SetScaling(VISU::Scaling theScaling){ + myScalarMapPL->SetScaling(theScaling); +} + + +void VISU::ScalarMap_i::SetRange(CORBA::Double theMin, CORBA::Double theMax){ + if(theMin > theMax) return; + float aScalarRange[2] = {theMin, theMax}; + myScalarMapPL->SetScalarRange(aScalarRange); + myIsFixedRange = true; +} + +CORBA::Double VISU::ScalarMap_i::GetMin(){ + return myScalarMapPL->GetScalarRange()[0]; +} + +CORBA::Double VISU::ScalarMap_i::GetMax(){ + return myScalarMapPL->GetScalarRange()[1]; +} + + +void VISU::ScalarMap_i::SetNbColors(CORBA::Long theNbColors){ + myScalarMapPL->SetNbColors(theNbColors); +} + +CORBA::Long VISU::ScalarMap_i::GetNbColors(){ + return myScalarMapPL->GetNbColors(); +} + + +VISU::ScalarMap_i::~ScalarMap_i(){} + + +VISU::Storable* VISU::ScalarMap_i::Build(int theRestoring){ + if(MYDEBUG) + MESSAGE("ScalarMap_i::Build - "<Init(); + if(!myIsFixedRange) myScalarMapPL->SetSourceRange(); + const VISU::TValField& aValField = myField->myValField; + const VISU::PValForTime aValForTime = aValField.find(myIteration)->second; + aComment.sprintf("%s %s",myFieldName.c_str(),VISU_Convertor::GenerateName(aValForTime->myTime).c_str()); + if (theRestoring == 0) myTitle = aComment.simplifyWhiteSpace().latin1(); + } + if(myAddToStudy){ + myName = GenerateName().latin1(); + aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", + VISU::TTIMESTAMP,myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp); + string aResultEntry = myResult->GetEntry(); + string aRefFatherEntry = myResult->GetRefFatherEntry(); + string anEntry = myResult->GetEntry(aComment.latin1()); + if(anEntry == "") throw std::runtime_error("There is no Entry for binding the presentation !!!"); + aComment.sprintf("myComment=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", + GetComment(),myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp); + CORBA::String_var anIOR = GetID(); + CreateAttributes(myStudy,anEntry.c_str(),aRefFatherEntry.c_str(),anIOR,myName.c_str(),"",aComment.latin1(),true); + mySObject = myStudy->FindObjectIOR(anIOR); + } + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<CommitCommand(); + return this; +} + + +void VISU::ScalarMap_i::DoSetInput(Result_i* theResult){ + if(theResult->GetInput() == NULL) + throw std::runtime_error("Mesh_i::Build - theResult->GetInput() == NULL !!!"); + myField = theResult->GetInput()->GetField(myMeshName,myEntity,myFieldName); + if(myField == NULL) + throw std::runtime_error("There is no Field with the parameters !!!"); + VISU_Convertor::TOutput *anOutput = + theResult->GetInput()->GetTimeStampOnMesh(myMeshName,myEntity,myFieldName,myIteration); + if(anOutput == NULL) + throw std::runtime_error("There is no TimeStamp with the parameters !!!"); + myScalarMapPL->SetInput(anOutput); + myScalarMapPL->Build(); +} + + +void VISU::ScalarMap_i::DoHook(){ + if(MYDEBUG) MESSAGE("ScalarMap_i::DoHook() - "<GetMapper()->SetScalarVisibility(1); + } + myScalarMapPL = dynamic_cast(myPipeLine); +} + +void VISU::ScalarMap_i::Update() { + VISU::Prs3d_i::Update(); +} + +void VISU::ScalarMap_i::SetMapScale(double theMapScale){ + myScalarMapPL->SetMapScale(theMapScale); +} + +VISU_Actor* VISU::ScalarMap_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) +{ + VISU_ScalarMapAct* anActor = VISU_ScalarMapAct::New(); + try{ + VISU::Prs3d_i::CreateActor(anActor,theIO); + anActor->SetBarVisibility(true); + anActor->SetRepresentation(2); + UpdateActor(anActor); + }catch(...){ + anActor->Delete(); + throw; + } + return anActor; +} + +void VISU::ScalarMap_i::UpdateActor(VISU_Actor* theActor) { + if(VISU_ScalarMapAct* anActor = dynamic_cast(theActor)){ + VISU::Prs3d_i::UpdateActor(theActor); + VISU_ScalarBarActor *aScalarBar = anActor->GetScalarBar(); + aScalarBar->SetLookupTable(myScalarMapPL->GetBarTable()); + aScalarBar->SetTitle(myTitle.c_str()); + aScalarBar->SetOrientation(myOrientation); + aScalarBar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport(); + aScalarBar->GetPositionCoordinate()->SetValue(myPosition[0],myPosition[1]); + aScalarBar->SetWidth(myWidth); + aScalarBar->SetHeight(myHeight); + aScalarBar->SetNumberOfLabels(myNumberOfLabels); + + vtkTextProperty* aTitleProp = aScalarBar->GetTitleTextProperty(); + aTitleProp->SetFontFamily(myTitFontType); + aTitleProp->SetColor(myTitleColor); + (myIsBoldTitle)? aTitleProp->BoldOn() : aTitleProp->BoldOff(); + (myIsItalicTitle)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff(); + (myIsShadowTitle)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff(); + + vtkTextProperty* aLabelProp = aScalarBar->GetLabelTextProperty(); + aLabelProp->SetFontFamily(myLblFontType); + aLabelProp->SetColor(myLabelColor); + (myIsBoldLabel)? aLabelProp->BoldOn() : aLabelProp->BoldOff(); + (myIsItalicLabel)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff(); + (myIsShadowLabel)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff(); + + aScalarBar->Modified(); + } +} + + +void VISU::ScalarMap_i::SetSourceRange(){ + myScalarMapPL->SetSourceRange(); + myIsFixedRange = false; +} diff --git a/src/VISU_I/VISU_ScalarMap_i.hh b/src/VISU_I/VISU_ScalarMap_i.hh new file mode 100644 index 00000000..3ff15020 --- /dev/null +++ b/src/VISU_I/VISU_ScalarMap_i.hh @@ -0,0 +1,205 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISU_PrsObject_i.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_ScalarMap_i_HeaderFile +#define VISU_ScalarMap_i_HeaderFile + +#include "VISU_Prs3d_i.hh" + +class VISU_ScalarMapPL; + +namespace VISU{ + class ScalarMap_i : public virtual POA_VISU::ScalarMap, + public virtual Prs3d_i + { + static int myNbPresent; + ScalarMap_i(); + ScalarMap_i(const ScalarMap_i&); + + public: + explicit + ScalarMap_i(Result_i* theResult, + bool theAddToStudy); + explicit + ScalarMap_i(Result_i* theResult, + SALOMEDS::SObject_ptr theSObject); + virtual void SameAs(const ScalarMap_i* theOrigin); + virtual ~ScalarMap_i(); + virtual void RemoveFromStudy(); + + virtual VISU::VISUType GetType() { return VISU::TSCALARMAP;}; + + virtual CORBA::Long GetScalarMode(); + virtual void SetScalarMode(CORBA::Long theScalarMode); + + virtual VISU::Scaling GetScaling(); + virtual void SetScaling(VISU::Scaling theScaling); + + virtual void SetRange(CORBA::Double theMin, CORBA::Double theMax); + virtual CORBA::Double GetMin(); + virtual CORBA::Double GetMax(); + + virtual void SetNbColors(CORBA::Long theNbColors); + virtual CORBA::Long GetNbColors(); + + virtual void SetBarOrientation(VISU::ScalarMap::Orientation theOrientation){ + myOrientation = theOrientation; + } + virtual VISU::ScalarMap::Orientation GetBarOrientation() { return myOrientation;} + + virtual void SetPosition(CORBA::Double X, CORBA::Double Y) { myPosition[0] = X; myPosition[1] = Y;} + virtual CORBA::Double GetPosX() { return myPosition[0];} + virtual CORBA::Double GetPosY() { return myPosition[1];} + + virtual void SetSize(CORBA::Double theWidth, CORBA::Double theHeight) { + myWidth = theWidth; myHeight = theHeight; + } + virtual CORBA::Double GetWidth() { return myWidth;} + virtual CORBA::Double GetHeight() { return myHeight;} + + virtual void SetLabels(CORBA::Long theNbLabels) { myNumberOfLabels = theNbLabels;} + virtual CORBA::Long GetLabels() { return myNumberOfLabels;} + + virtual void SetTitle(const char* theName) { myTitle = theName;} + virtual char* GetTitle() { return CORBA::string_dup(myTitle.c_str());} + + virtual bool IsBoldTitle() { return myIsBoldTitle;} + virtual void SetBoldTitle(bool isBold) { myIsBoldTitle = isBold;} + + virtual bool IsItalicTitle() { return myIsItalicTitle;} + virtual void SetItalicTitle(bool isItalic) { myIsItalicTitle = isItalic;} + + virtual bool IsShadowTitle() { return myIsShadowTitle;} + virtual void SetShadowTitle(bool isShadow) { myIsShadowTitle = isShadow;} + + virtual int GetTitFontType() { return myTitFontType;} + virtual void SetTitFontType(int theType) { myTitFontType = theType;} + + virtual void GetTitleColor(float* theR, float* theG, float* theB) + {*theR = myTitleColor[0]; *theG = myTitleColor[1]; *theB = myTitleColor[2];} + virtual void SetTitleColor(float theR, float theG, float theB) + {myTitleColor[0] = theR; myTitleColor[1] = theG; myTitleColor[2] = theB; } + + ///// + virtual bool IsBoldLabel() { return myIsBoldLabel;} + virtual void SetBoldLabel(bool isBold) { myIsBoldLabel = isBold;} + + virtual bool IsItalicLabel() { return myIsItalicLabel;} + virtual void SetItalicLabel(bool isItalic) { myIsItalicLabel = isItalic;} + + virtual bool IsShadowLabel() { return myIsShadowLabel;} + virtual void SetShadowLabel(bool isShadow) {myIsShadowLabel = isShadow;} + + virtual int GetLblFontType() { return myLblFontType;} + virtual void SetLblFontType(int theType) { myLblFontType = theType;} + + virtual void GetLabelColor(float* theR, float* theG, float* theB) + {*theR = myLabelColor[0]; *theG = myLabelColor[1]; *theB = myLabelColor[2];} + virtual void SetLabelColor(float theR, float theG, float theB) + {myLabelColor[0] = theR; myLabelColor[1] = theG; myLabelColor[2] = theB; } + + typedef VISU::ScalarMap TInterface; + VISU_ScalarMapPL* GetScalarMapPL(){ return myScalarMapPL;} + + /*! + * \brief Works like SameAs() method, but keep myIteration value unchanged. + * + * Is used in VISU_TimeAnimation class implementation. + */ + void SameAsParams (const ScalarMap_i* theOrigin); + + protected: + Storable* Build(int theRestoring); + virtual void DoSetInput(Result_i* theResult); + virtual void DoHook(); + + VISU_ScalarMapPL* myScalarMapPL; + PField myField; + + // std::string myMeshName; move it to Prs3d_i + TEntity myEntity; + std::string myFieldName; + int myIteration; + + bool myIsFixedRange; + + std::string myTitle; + int myNumberOfLabels; + float myPosition[2], myWidth, myHeight; + VISU::ScalarMap::Orientation myOrientation; + + //Font management + bool myIsBoldTitle; + bool myIsItalicTitle; + bool myIsShadowTitle; + int myTitFontType; + float myTitleColor[3]; + + bool myIsBoldLabel; + bool myIsItalicLabel; + bool myIsShadowLabel; + int myLblFontType; + float myLabelColor[3]; + + public: + static int IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration, int isMemoryCheck = true); + virtual Storable* Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + + const std::string& GetMeshName() const { return myMeshName;} + VISU::Entity GetEntity() const { return VISU::Entity(myEntity);} + const string& GetFieldName() const { return myFieldName;} + int GetIteration() const { return myIteration;} + + virtual void ToStream(std::ostringstream& theStr); + + static const std::string myComment; + virtual const char* GetComment() const; + virtual QString GenerateName(); + + virtual Storable* Restore(const Storable::TRestoringMap& theMap); + + static Storable* Restore(SALOMEDS::SObject_ptr theSObject, + const std::string& thePrefix, const Storable::TRestoringMap& theMap); + + virtual void Update() ; + virtual void SetMapScale(double theMapScale = 1.0); + + const VISU::PField GetField() const { return myField;} + + virtual bool IsRangeFixed() { return myIsFixedRange; } + virtual void SetSourceRange(); + + virtual int GetIteration() { return myIteration; } + + virtual VISU_Actor* CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); + + virtual void UpdateActor(VISU_Actor* theActor) ; + }; +} + +#endif