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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : VISU_PrsObject_i.cxx
24 // Author : Alexey PETROV
27 #include "VISU_Mesh_i.hh"
28 #include "VISU_Prs3dUtils.hh"
30 #include "VISU_Result_i.hh"
32 #include "VISU_MeshAct.h"
33 #include "VISU_MeshPL.hxx"
34 #include "VISU_PipeLineUtils.hxx"
35 #include "VISU_Convertor.hxx"
37 #include "SALOME_Event.hxx"
39 #include "SUIT_ResourceMgr.h"
42 static int MYDEBUG = 0;
44 static int MYDEBUG = 0;
47 static int INCMEMORY = 4;
49 //----------------------------------------------------------------------------
53 IsSameColor(const SALOMEDS::Color& theLeft,
54 const SALOMEDS::Color& theRight)
57 VISU::CheckIsSameValue(theLeft.R, theRight.R) &&
58 VISU::CheckIsSameValue(theLeft.G, theRight.G) &&
59 VISU::CheckIsSameValue(theLeft.B, theRight.B);
63 //----------------------------------------------------------------------------
64 int VISU::Mesh_i::myNbPresent = 0;
66 //----------------------------------------------------------------------------
71 return VISU::GenerateName("Mesh", myNbPresent++);
74 //----------------------------------------------------------------------------
75 const string VISU::Mesh_i::myComment = "MESH";
77 //----------------------------------------------------------------------------
82 return myComment.c_str();
85 //----------------------------------------------------------------------------
88 myMeshPL(VISU_MeshPL::New())
90 SetPipeLine(myMeshPL);
94 //----------------------------------------------------------------------------
97 ::IsPossible(Result_i* theResult,
98 const std::string& theMeshName,
100 const std::string& theFamilyName)
103 MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theEntity = "<<theEntity<<"; theFamilyName = '"<<theFamilyName<<"'");
104 size_t aSize = INCMEMORY*
105 theResult->GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity);
106 size_t aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
107 MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
109 }catch(std::exception& exc){
110 INFOS("Follow exception was occured :\n"<<exc.what());
112 INFOS("Unknown exception was occured!");
118 //----------------------------------------------------------------------------
121 ::Create(VISU::Result_i* theResult,
122 const std::string& theMeshName,
123 VISU::Entity theEntity,
124 const std::string& theFamilyName)
126 SetCResult(theResult);
127 SetMeshName(theMeshName.c_str());
128 myEntity = int(theEntity);//jfa IPAL9284
129 mySubMeshName = theFamilyName;
134 //----------------------------------------------------------------------------
137 ::IsPossible(Result_i* theResult,
138 const std::string& theMeshName,
139 const std::string& theGroupName)
142 MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theGroupName = '"<<theGroupName<<"'");
143 size_t aSize = INCMEMORY*
144 theResult->GetInput()->GetMeshOnGroupSize(theMeshName,theGroupName);
145 size_t aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
146 INFOS("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
148 }catch(std::exception& exc){
149 INFOS("Follow exception was occured :\n"<<exc.what());
151 INFOS("Unknown exception was occured!");
157 //----------------------------------------------------------------------------
160 ::Create(VISU::Result_i* theResult,
161 const std::string& theMeshName,
162 const std::string& theGroupName)
164 SetCResult(theResult);
165 SetMeshName(theMeshName.c_str());
166 myEntity = -1;//jfa IPAL9284
167 mySubMeshName = theGroupName;
172 //----------------------------------------------------------------------------
176 if(MYDEBUG) MESSAGE("Mesh_i::~Mesh_i()");
180 //----------------------------------------------------------------------------
183 ::Build(int theRestoring)
185 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
186 aStudyBuilder->NewCommand(); // There is a transaction
188 if (GetCResult()->GetInput() == NULL)
189 throw std::runtime_error("Mesh_i::Build - GetCResult()->GetInput() == NULL !!!");
191 myPresentType = VISU::PresentationType(VISU::GetResourceMgr()->integerValue("VISU" , "mesh_represent", 2));
192 if(myEntity == VISU::NODE_ENTITY)
193 myPresentType = VISU::POINT;
194 SetName(GenerateName().latin1(), false);
195 myCellColor.R = 0.0; myCellColor.G = myCellColor.B = 1.0;
196 myNodeColor.R = myNodeColor.G = 1.0; myNodeColor.B = 1.0;
197 myLinkColor.R = myLinkColor.G = myLinkColor.B = 83/255.;
201 if(mySubMeshName == "")
202 myType = VISU::TENTITY;
204 myType = VISU::TFAMILY;
206 myType = VISU::TGROUP;
208 if(MYDEBUG) MESSAGE("Mesh_i::Build - myType = "<<myType);
209 QString aComment,aTmp;
211 std::string aMeshName = GetCMeshName();
212 VISU::TEntity anEntity = VISU::TEntity(myEntity);
214 VISU::Storable::TRestoringMap aRestoringMap;
215 aRestoringMap["myMeshName"] = GetCMeshName();
217 VISU::PUnstructuredGridIDMapper anIDMapper;
218 VISU::Result_i::PInput anInput = GetCResult()->GetInput();
221 anIDMapper = anInput->GetMeshOnEntity(aMeshName,
222 anEntity);//jfa IPAL9284
223 aRestoringMap["myComment"] = "ENTITY";
224 aRestoringMap["myId"] = QString::number(anEntity);
227 anIDMapper = anInput->GetFamilyOnEntity(aMeshName,
230 aRestoringMap["myComment"] = "FAMILY";
231 aRestoringMap["myEntityId"] = QString::number(anEntity);
232 aRestoringMap["myName"] = mySubMeshName;
235 anIDMapper = anInput->GetMeshOnGroup(GetCMeshName(),
237 aRestoringMap["myComment"] = "GROUP";
238 aRestoringMap["myName"] = mySubMeshName;
242 throw std::runtime_error("Mesh_i::Build - !anIDMapper !!!");
244 myMeshPL->SetUnstructuredGridIDMapper(anIDMapper);
246 string anEntry = GetCResult()->GetEntry(aRestoringMap);
248 throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!");
249 SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectID(anEntry.c_str());
251 if(!theRestoring) { //Setting IOR on the label
253 string aResultEntry = GetCResult()->GetEntry();
254 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
255 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
256 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
257 CORBA::String_var aString = GetID();
258 anIOR->SetValue(aString);
262 SALOMEDS::GenericAttribute_var anAttr;
263 SALOMEDS::AttributePixMap_var aPixmap;
265 anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributePixMap");
266 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
267 aPixmap->SetPixMap("ICON_TREE_MESH");
269 }catch(std::exception& exc){
270 INFOS("Follow exception was occured :\n"<<exc.what());
273 INFOS("Unknown exception was occured!");
276 aStudyBuilder->CommitCommand();
281 //---------------------------------------------------------------
284 ::SameAs(const VISU::Prs3d_i* theOrigin)
286 return; // "SameAs" command for mesh is not valid in current architecture
290 //---------------------------------------------------------------
295 struct TRemoveFromStudy: public SALOME_Event
297 VISU::Mesh_i* myRemovable;
298 TRemoveFromStudy(VISU::Mesh_i* theRemovable):
299 myRemovable(theRemovable)
306 VISU::RemoveFromStudy(myRemovable->GetSObject());
307 myRemovable->TSuperClass::RemoveFromStudy();
312 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
313 aStudyBuilder->RemoveAttribute(GetSObject(), "AttributePixMap");
315 ProcessVoidEvent(new TRemoveFromStudy(this));
319 //----------------------------------------------------------------------------
322 ::SetCellColor(const SALOMEDS::Color& theColor)
324 if(IsSameColor(myCellColor, theColor))
327 VISU::TSetModified aModified(this);
329 myCellColor = theColor;
330 myParamsTime.Modified();
334 //----------------------------------------------------------------------------
343 //----------------------------------------------------------------------------
346 ::SetNodeColor(const SALOMEDS::Color& theColor)
348 if(IsSameColor(myNodeColor, theColor))
351 VISU::TSetModified aModified(this);
353 myNodeColor = theColor;
354 myParamsTime.Modified();
358 //----------------------------------------------------------------------------
367 //----------------------------------------------------------------------------
370 ::SetLinkColor(const SALOMEDS::Color& theColor)
372 if(IsSameColor(myLinkColor, theColor))
375 VISU::TSetModified aModified(this);
377 myLinkColor = theColor;
378 myParamsTime.Modified();
382 //----------------------------------------------------------------------------
391 //----------------------------------------------------------------------------
394 ::SetPresentationType(VISU::PresentationType theType)
396 if(myPresentType == theType)
399 VISU::TSetModified aModified(this);
401 myPresentType = theType;
402 myParamsTime.Modified();
406 //----------------------------------------------------------------------------
407 VISU::PresentationType
409 ::GetPresentationType()
411 return myPresentType;
415 //----------------------------------------------------------------------------
420 return VISU::Entity(myEntity);
424 //----------------------------------------------------------------------------
427 ::GetSubMeshName() const
429 return mySubMeshName;
433 //----------------------------------------------------------------------------
436 ::Restore(SALOMEDS::SObject_ptr theSObject,
437 const Storable::TRestoringMap& theMap)
439 if(!TSuperClass::Restore(theSObject, theMap))
442 myEntity = VISU::Storable::FindValue(theMap,"myEntity").toInt();//jfa IPAL9284
443 mySubMeshName = VISU::Storable::FindValue(theMap,"mySubMeshName").latin1();
445 myPresentType = VISU::PresentationType(VISU::Storable::FindValue(theMap,"myPresentType").toInt());
447 myCellColor.R = VISU::Storable::FindValue(theMap,"myCellColor.R").toDouble();
448 myCellColor.G = VISU::Storable::FindValue(theMap,"myCellColor.G").toDouble();
449 myCellColor.B = VISU::Storable::FindValue(theMap,"myCellColor.B").toDouble();
451 myNodeColor.R = VISU::Storable::FindValue(theMap,"myNodeColor.R").toDouble();
452 myNodeColor.G = VISU::Storable::FindValue(theMap,"myNodeColor.G").toDouble();
453 myNodeColor.B = VISU::Storable::FindValue(theMap,"myNodeColor.B").toDouble();
455 myLinkColor.R = VISU::Storable::FindValue(theMap,"myLinkColor.R").toDouble();
456 myLinkColor.G = VISU::Storable::FindValue(theMap,"myLinkColor.G").toDouble();
457 myLinkColor.B = VISU::Storable::FindValue(theMap,"myLinkColor.B").toDouble();
463 //----------------------------------------------------------------------------
466 ::StorableEngine(SALOMEDS::SObject_ptr theSObject,
467 const Storable::TRestoringMap& theMap,
468 const std::string& thePrefix,
469 CORBA::Boolean theIsMultiFile)
471 Mesh_i* aMesh = new Mesh_i();
472 return aMesh->Restore(theSObject, theMap);
476 //----------------------------------------------------------------------------
479 ::ToStream(std::ostringstream& theStr)
481 TSuperClass::ToStream(theStr);
483 Storable::DataToStream( theStr, "myEntity", myEntity );
484 Storable::DataToStream( theStr, "mySubMeshName", mySubMeshName.c_str() );
486 Storable::DataToStream( theStr, "myPresentType", int(myPresentType) );
488 Storable::DataToStream( theStr, "myCellColor.R", myCellColor.R );
489 Storable::DataToStream( theStr, "myCellColor.G", myCellColor.G );
490 Storable::DataToStream( theStr, "myCellColor.B", myCellColor.B );
492 Storable::DataToStream( theStr, "myNodeColor.R", myNodeColor.R );
493 Storable::DataToStream( theStr, "myNodeColor.G", myNodeColor.G );
494 Storable::DataToStream( theStr, "myNodeColor.B", myNodeColor.B );
496 Storable::DataToStream( theStr, "myLinkColor.R", myLinkColor.R );
497 Storable::DataToStream( theStr, "myLinkColor.G", myLinkColor.G );
498 Storable::DataToStream( theStr, "myLinkColor.B", myLinkColor.B );
502 //----------------------------------------------------------------------------
507 VISU_MeshAct* anActor = VISU_MeshAct::New();
509 VISU::Prs3d_i::CreateActor(anActor);
510 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
511 bool toShrink = aResourceMgr->booleanValue("VISU", "mesh_shrink", false);
512 if (toShrink) anActor->SetShrink();
513 UpdateActor(anActor);
522 //----------------------------------------------------------------------------
525 ::UpdateActor(VISU_Actor* theActor)
527 if(VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(theActor)){
528 if(MYDEBUG) MESSAGE("Mesh_i::UpdateActor");
529 VISU::Prs3d_i::UpdateActor(anActor);
530 anActor->SetRepresentation(myPresentType);
531 anActor->GetSurfaceProperty()->SetColor(myCellColor.R, myCellColor.G, myCellColor.B);
532 anActor->GetEdgeProperty()->SetColor(myLinkColor.R, myLinkColor.G, myLinkColor.B);
533 anActor->GetNodeProperty()->SetColor(myNodeColor.R, myNodeColor.G, myNodeColor.B);
537 //----------------------------------------------------------------------------