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_MeshPL.hxx"
28 #include "VISU_Result_i.hh"
29 #include "VISU_Mesh_i.hh"
30 #include "VISU_MeshAct.h"
36 static int MYDEBUG = 0;
37 static int MYDEBUGWITHFILES = 0;
39 static int MYDEBUG = 0;
40 static int MYDEBUGWITHFILES = 0;
43 static int INCMEMORY = 4;
45 int VISU::Mesh_i::myNbPresent = 0;
47 QString VISU::Mesh_i::GenerateName() { return VISU::GenerateName("Mesh",myNbPresent++);}
49 const string VISU::Mesh_i::myComment = "MESH";
51 const char* VISU::Mesh_i::GetComment() const { return myComment.c_str();}
53 VISU::Mesh_i::Mesh_i(Result_i* theResult, SALOMEDS::SObject_ptr theSObject) :
54 PrsObject_i(theResult->GetStudyDocument()),
55 Prs3d_i(theResult,theSObject)
57 myPipeLine = myMeshPL = VISU_MeshPL::New();;
61 void VISU::Mesh_i::RemoveFromStudy(){
62 VISU::RemoveFromStudy(mySObject);
66 void VISU::Mesh_i::SameAs(const Mesh_i* theOrigin){
67 return; // "SameAs" command for mesh is not valid in current architecture
72 int VISU::Mesh_i::IsPossible(Result_i* theResult, const char* theMeshName, Entity theEntity, const char* theFamilyName){
74 INFOS("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theEntity = "<<theEntity<<"; theFamilyName = '"<<theFamilyName<<"'");
75 float aSize = INCMEMORY*
76 theResult->GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity,theFamilyName);
77 bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
78 INFOS("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
80 }catch(std::runtime_error& exc){
81 INFOS("Follow exception was accured :\n"<<exc.what());
83 INFOS("Unknown exception was accured!");
88 VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, Entity theEntity, const char* theFamilyName){
89 myMeshName = theMeshName;
90 myEntity = VISU::TEntity(theEntity);
91 mySubMeshName = theFamilyName;
96 int VISU::Mesh_i::IsPossible(Result_i* theResult, const char* theMeshName, const char* theGroupName){
98 INFOS("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theGroupName = '"<<theGroupName<<"'");
99 float aSize = INCMEMORY*
100 theResult->GetInput()->GetMeshOnGroupSize(theMeshName,theGroupName);
101 bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
102 INFOS("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
104 }catch(std::runtime_error& exc){
105 INFOS("Follow exception was accured :\n"<<exc.what());
107 INFOS("Unknown exception was accured!");
113 VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, const char* theGroupName){
114 myMeshName = theMeshName;
115 myEntity = VISU::TEntity(-1);
116 mySubMeshName = theGroupName;
121 VISU::Storable* VISU::Mesh_i::Restore(const Storable::TRestoringMap& theMap)
122 throw(std::logic_error&)
124 Prs3d_i::Restore(theMap);
126 myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1();
127 myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt();
128 mySubMeshName = VISU::Storable::FindValue(theMap,"mySubMeshName").latin1();
130 myPresentType = VISU::PresentationType(VISU::Storable::FindValue(theMap,"myPresentType").toInt());
132 myCellColor.R = VISU::Storable::FindValue(theMap,"myCellColor.R").toDouble();
133 myCellColor.G = VISU::Storable::FindValue(theMap,"myCellColor.G").toDouble();
134 myCellColor.B = VISU::Storable::FindValue(theMap,"myCellColor.B").toDouble();
136 myNodeColor.R = VISU::Storable::FindValue(theMap,"myNodeColor.R").toDouble();
137 myNodeColor.G = VISU::Storable::FindValue(theMap,"myNodeColor.G").toDouble();
138 myNodeColor.B = VISU::Storable::FindValue(theMap,"myNodeColor.B").toDouble();
140 myLinkColor.R = VISU::Storable::FindValue(theMap,"myLinkColor.R").toDouble();
141 myLinkColor.G = VISU::Storable::FindValue(theMap,"myLinkColor.G").toDouble();
142 myLinkColor.B = VISU::Storable::FindValue(theMap,"myLinkColor.B").toDouble();
148 void VISU::Mesh_i::ToStream(std::ostringstream& theStr){
149 Prs3d_i::ToStream(theStr);
151 Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() );
152 Storable::DataToStream( theStr, "myEntity", myEntity );
153 Storable::DataToStream( theStr, "mySubMeshName", mySubMeshName.c_str() );
155 Storable::DataToStream( theStr, "myPresentType", int(myPresentType) );
157 Storable::DataToStream( theStr, "myCellColor.R", myCellColor.R );
158 Storable::DataToStream( theStr, "myCellColor.G", myCellColor.G );
159 Storable::DataToStream( theStr, "myCellColor.B", myCellColor.B );
161 Storable::DataToStream( theStr, "myNodeColor.R", myNodeColor.R );
162 Storable::DataToStream( theStr, "myNodeColor.G", myNodeColor.G );
163 Storable::DataToStream( theStr, "myNodeColor.B", myNodeColor.B );
165 Storable::DataToStream( theStr, "myLinkColor.R", myLinkColor.R );
166 Storable::DataToStream( theStr, "myLinkColor.G", myLinkColor.G );
167 Storable::DataToStream( theStr, "myLinkColor.B", myLinkColor.B );
171 VISU::Mesh_i::~Mesh_i(){
172 if(MYDEBUG) MESSAGE("Mesh_i::~Mesh_i()");
176 VISU::Storable* VISU::Mesh_i::Build(int theRestoring){
177 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
178 aStudyBuilder->NewCommand(); // There is a transaction
180 if(myResult->GetInput() == NULL)
181 throw std::runtime_error("Mesh_i::Build - myResult->GetInput() == NULL !!!");
183 myPresentType = VISU::SHADED;
184 myName = GenerateName().latin1();
185 myCellColor.R = 0.0; myCellColor.G = myCellColor.B = 1.0;
186 myNodeColor.R = myNodeColor.G = 1.0; myNodeColor.B = 1.0;
187 myLinkColor.R = myLinkColor.G = myLinkColor.B = 83/255.;
189 if(int(myEntity) >= 0)
190 if(mySubMeshName == "")
191 myType = VISU::TENTITY;
193 myType = VISU::TFAMILY;
195 myType = VISU::TGROUP;
196 if(MYDEBUG) MESSAGE("Mesh_i::Build - myType = "<<myType);
199 VISU_Convertor::TOutput *anOutput;
202 anOutput = myResult->GetInput()->GetMeshOnEntity(myMeshName,myEntity);
203 aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
204 VISU::TENTITY,myMeshName.c_str(),myEntity);
207 anOutput = myResult->GetInput()->GetMeshOnEntity(myMeshName,myEntity,mySubMeshName);
208 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
209 VISU::TFAMILY,myMeshName.c_str(),myEntity,mySubMeshName.c_str());
212 anOutput = myResult->GetInput()->GetMeshOnGroup(myMeshName,mySubMeshName);
213 aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
214 VISU::TGROUP,myMeshName.c_str(),mySubMeshName.c_str());
217 if(anOutput == NULL) throw std::runtime_error("Mesh_i::Build - anOutput == NULL !!!");
218 myMeshPL->SetInput(anOutput);
220 if(!theRestoring) { //Setting IOR on the label
222 string aResultEntry = myResult->GetEntry();
223 string anEntry = FindEntryWithComment(myStudy,aResultEntry.c_str(),aComment.latin1());
224 if(anEntry == "") throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!");
225 mySObject = myStudy->FindObjectID(anEntry.c_str());
226 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
227 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(mySObject,"AttributeIOR");
228 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
229 CORBA::String_var aString = GetID();
230 anIOR->SetValue(aString);
232 }catch(std::runtime_error& exc){
233 INFOS("Follow exception was accured :\n"<<exc.what());
236 INFOS("Unknown exception was accured!");
239 aStudyBuilder->CommitCommand();
244 VISU_Actor* VISU::Mesh_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
245 throw (std::runtime_error&)
247 VISU_MeshAct* anActor = VISU_MeshAct::New();
249 VISU::Prs3d_i::CreateActor(anActor,theIO);
250 UpdateActor(anActor);
251 }catch(std::runtime_error& exc){
259 void VISU::Mesh_i::UpdateActor(VISU_Actor* theActor) throw(std::runtime_error&){
260 if(VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(theActor)){
261 if(MYDEBUG) MESSAGE("Mesh_i::UpdateActor");
262 VISU::Prs3d_i::UpdateActor(anActor);
263 anActor->SetRepresentation(myPresentType);
264 anActor->GetProperty()->SetColor(myCellColor.R, myCellColor.G, myCellColor.B);
265 anActor->GetEdgeProperty()->SetColor(myLinkColor.R, myLinkColor.G, myLinkColor.B);
266 anActor->GetNodeProperty()->SetColor(myNodeColor.R, myNodeColor.G, myNodeColor.B);