1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // VISU OBJECT : interactive object for VISU entities implementation
24 // File : VISU_PrsObject_i.cxx
25 // Author : Alexey PETROV
28 #include "VISU_Mesh_i.hh"
29 #include "VISU_Prs3dUtils.hh"
31 #include "VISU_Result_i.hh"
33 #include "VISU_MeshAct.h"
34 #include "VISU_MeshPL.hxx"
35 #include "VISU_PipeLineUtils.hxx"
36 #include "VISU_Convertor.hxx"
38 #include "SALOME_Event.h"
40 #include "SUIT_ResourceMgr.h"
43 static int MYDEBUG = 0;
45 static int MYDEBUG = 0;
48 static int INCMEMORY = 4;
52 //----------------------------------------------------------------------------
56 IsSameColor(const SALOMEDS::Color& theLeft,
57 const SALOMEDS::Color& theRight)
60 VISU::CheckIsSameValue(theLeft.R, theRight.R) &&
61 VISU::CheckIsSameValue(theLeft.G, theRight.G) &&
62 VISU::CheckIsSameValue(theLeft.B, theRight.B);
66 //----------------------------------------------------------------------------
67 int VISU::Mesh_i::myNbPresent = 0;
69 //----------------------------------------------------------------------------
74 return VISU::GenerateName("Mesh", myNbPresent++);
77 //----------------------------------------------------------------------------
78 const string VISU::Mesh_i::myComment = "MESH";
80 //----------------------------------------------------------------------------
85 return myComment.c_str();
88 //----------------------------------------------------------------------------
91 myMeshPL(VISU_MeshPL::New())
93 SetPipeLine(myMeshPL);
97 //----------------------------------------------------------------------------
100 ::IsPossible(Result_i* theResult,
101 const std::string& theMeshName,
103 const std::string& theFamilyName)
106 MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theEntity = "<<theEntity<<"; theFamilyName = '"<<theFamilyName<<"'");
107 size_t aSize = INCMEMORY*
108 theResult->GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity);
109 size_t aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
110 MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
112 }catch(std::exception& exc){
113 INFOS("Follow exception was occured :\n"<<exc.what());
115 INFOS("Unknown exception was occured!");
121 //----------------------------------------------------------------------------
124 ::Create(VISU::Result_i* theResult,
125 const std::string& theMeshName,
126 VISU::Entity theEntity,
127 const std::string& theFamilyName)
129 SetCResult(theResult);
130 SetMeshName(theMeshName.c_str());
131 myEntity = int(theEntity);//jfa IPAL9284
132 mySubMeshName = theFamilyName;
133 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
134 myIsShrank = aResourceMgr->booleanValue("VISU", "mesh_shrink", false);
139 //----------------------------------------------------------------------------
142 ::IsPossible(Result_i* theResult,
143 const std::string& theMeshName,
144 const std::string& theGroupName)
147 MESSAGE("Mesh_i::IsPossible - theMeshName = '"<<theMeshName<<"'; theGroupName = '"<<theGroupName<<"'");
148 size_t aSize = INCMEMORY*
149 theResult->GetInput()->GetMeshOnGroupSize(theMeshName,theGroupName);
150 size_t aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
151 INFOS("Mesh_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
153 }catch(std::exception& exc){
154 INFOS("Follow exception was occured :\n"<<exc.what());
156 INFOS("Unknown exception was occured!");
162 //----------------------------------------------------------------------------
165 ::Create(VISU::Result_i* theResult,
166 const std::string& theMeshName,
167 const std::string& theGroupName)
169 SetCResult(theResult);
170 SetMeshName(theMeshName.c_str());
171 myEntity = -1;//jfa IPAL9284
172 mySubMeshName = theGroupName;
177 //----------------------------------------------------------------------------
181 if(MYDEBUG) MESSAGE("Mesh_i::~Mesh_i()");
185 //----------------------------------------------------------------------------
188 ::Build(int theRestoring)
190 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
191 aStudyBuilder->NewCommand(); // There is a transaction
193 if (GetCResult()->GetInput() == NULL)
194 throw std::runtime_error("Mesh_i::Build - GetCResult()->GetInput() == NULL !!!");
196 myPresentType = VISU::PresentationType(VISU::GetResourceMgr()->integerValue("VISU" , "mesh_represent", 2));
197 myIsShrank = (myPresentType == VISU::SHRINK);
199 if(myEntity == VISU::NODE_ENTITY)
200 myPresentType = VISU::POINT;
201 SetName((const char*)GenerateName().toLatin1(), false);
202 myCellColor.R = 0.0; myCellColor.G = myCellColor.B = 1.0;
203 myNodeColor.R = myNodeColor.G = 1.0; myNodeColor.B = 1.0;
205 QColor aColor = VISU::GetResourceMgr()->colorValue( "VISU", "edge_color", QColor( 255, 255, 255 ) );
206 SALOMEDS::Color aLinkColor;
207 aLinkColor.R = aColor.red()/255.;
208 aLinkColor.G = aColor.green()/255.;
209 aLinkColor.B = aColor.blue()/255.;
210 SetLinkColor(aLinkColor);
212 my2DQuadPrsType = VISU::Quadratic2DPresentationType(VISU::GetResourceMgr()->integerValue( "VISU", "quadratic_mode", 0));
216 if(mySubMeshName == "")
217 myType = VISU::TENTITY;
219 myType = VISU::TFAMILY;
221 myType = VISU::TGROUP;
223 if(MYDEBUG) MESSAGE("Mesh_i::Build - myType = "<<myType);
224 QString aComment,aTmp;
226 std::string aMeshName = GetCMeshName();
227 VISU::TEntity anEntity = VISU::TEntity(myEntity);
229 VISU::Storable::TRestoringMap aRestoringMap;
230 aRestoringMap["myMeshName"] = GetCMeshName().c_str();
232 VISU::PUnstructuredGridIDMapper anIDMapper;
233 VISU::Result_i::PInput anInput = GetCResult()->GetInput();
236 anIDMapper = anInput->GetMeshOnEntity(aMeshName,
237 anEntity);//jfa IPAL9284
238 aRestoringMap["myComment"] = "ENTITY";
239 aRestoringMap["myId"] = QString::number(anEntity);
242 anIDMapper = anInput->GetFamilyOnEntity(aMeshName,
245 aRestoringMap["myComment"] = "FAMILY";
246 aRestoringMap["myEntityId"] = QString::number(anEntity);
247 aRestoringMap["myName"] = mySubMeshName.c_str();
250 anIDMapper = anInput->GetMeshOnGroup(GetCMeshName(),
252 aRestoringMap["myComment"] = "GROUP";
253 aRestoringMap["myName"] = mySubMeshName.c_str();
257 throw std::runtime_error("Mesh_i::Build - !anIDMapper !!!");
259 myMeshPL->SetUnstructuredGridIDMapper(anIDMapper);
261 string anEntry = GetCResult()->GetEntry(aRestoringMap);
263 throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!");
264 SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectID(anEntry.c_str());
266 if(!theRestoring) { //Setting IOR on the label
268 string aResultEntry = GetCResult()->GetEntry();
269 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
270 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
271 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
272 CORBA::String_var aString = GetID();
273 anIOR->SetValue(aString);
277 SALOMEDS::GenericAttribute_var anAttr;
278 SALOMEDS::AttributePixMap_var aPixmap;
280 anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributePixMap");
281 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
282 aPixmap->SetPixMap("ICON_TREE_MESH");
284 }catch(std::exception& exc){
285 INFOS("Follow exception was occured :\n"<<exc.what());
288 INFOS("Unknown exception was occured!");
291 aStudyBuilder->CommitCommand();
296 //---------------------------------------------------------------
299 ::SameAs(const VISU::Prs3d_i* theOrigin)
301 return; // "SameAs" command for mesh is not valid in current architecture
305 //---------------------------------------------------------------
310 struct TRemoveFromStudy: public SALOME_Event
312 VISU::Mesh_i* myRemovable;
313 TRemoveFromStudy(VISU::Mesh_i* theRemovable):
314 myRemovable(theRemovable)
321 VISU::RemoveFromStudy(myRemovable->GetSObject());
322 myRemovable->TSuperClass::RemoveFromStudy();
327 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
328 aStudyBuilder->RemoveAttribute(GetSObject(), "AttributePixMap");
330 ProcessVoidEvent(new TRemoveFromStudy(this));
334 //----------------------------------------------------------------------------
337 ::SetCellColor(const SALOMEDS::Color& theColor)
339 if(IsSameColor(myCellColor, theColor))
342 VISU::TSetModified aModified(this);
344 myCellColor = theColor;
345 myParamsTime.Modified();
349 //----------------------------------------------------------------------------
358 //----------------------------------------------------------------------------
361 ::SetNodeColor(const SALOMEDS::Color& theColor)
363 if(IsSameColor(myNodeColor, theColor))
366 VISU::TSetModified aModified(this);
368 myNodeColor = theColor;
369 myParamsTime.Modified();
373 //----------------------------------------------------------------------------
382 //----------------------------------------------------------------------------
385 ::SetLinkColor(const SALOMEDS::Color& theColor)
387 if(IsSameColor(myLinkColor, theColor))
390 VISU::TSetModified aModified(this);
392 myLinkColor = theColor;
393 myParamsTime.Modified();
397 //----------------------------------------------------------------------------
406 //----------------------------------------------------------------------------
409 ::SetPresentationType(VISU::PresentationType theType)
411 if(myPresentType == theType)
414 VISU::TSetModified aModified(this);
415 if (theType == VISU::SHRINK) {
418 myPresentType = theType;
419 myParamsTime.Modified();
425 ::SetQuadratic2DPresentationType(VISU::Quadratic2DPresentationType theType)
427 if(my2DQuadPrsType == theType)
430 VISU::TSetModified aModified(this);
431 my2DQuadPrsType = theType;
432 myParamsTime.Modified();
436 //----------------------------------------------------------------------------
437 VISU::PresentationType
439 ::GetPresentationType()
441 return myPresentType;
445 //----------------------------------------------------------------------------
446 VISU::Quadratic2DPresentationType
448 ::GetQuadratic2DPresentationType()
450 return my2DQuadPrsType;
456 //----------------------------------------------------------------------------
461 return VISU::Entity(myEntity);
465 //----------------------------------------------------------------------------
468 ::GetSubMeshName() const
470 return mySubMeshName;
474 //----------------------------------------------------------------------------
477 ::Restore(SALOMEDS::SObject_ptr theSObject,
478 const Storable::TRestoringMap& theMap)
480 if(!TSuperClass::Restore(theSObject, theMap))
483 myEntity = VISU::Storable::FindValue(theMap,"myEntity").toInt();//jfa IPAL9284
484 mySubMeshName = (const char*)VISU::Storable::FindValue(theMap,"mySubMeshName").toLatin1();
486 myPresentType = VISU::PresentationType(VISU::Storable::FindValue(theMap,"myPresentType").toInt());
488 my2DQuadPrsType = VISU::Quadratic2DPresentationType(VISU::Storable::FindValue(theMap,"my2DQuadPrsType").toInt());
490 myIsShrank = (VISU::Storable::FindValue(theMap,"myIsShrank", "0").toInt() == 1)? true: false;
492 myCellColor.R = VISU::Storable::FindValue(theMap,"myCellColor.R").toDouble();
493 myCellColor.G = VISU::Storable::FindValue(theMap,"myCellColor.G").toDouble();
494 myCellColor.B = VISU::Storable::FindValue(theMap,"myCellColor.B").toDouble();
496 myNodeColor.R = VISU::Storable::FindValue(theMap,"myNodeColor.R").toDouble();
497 myNodeColor.G = VISU::Storable::FindValue(theMap,"myNodeColor.G").toDouble();
498 myNodeColor.B = VISU::Storable::FindValue(theMap,"myNodeColor.B").toDouble();
500 myLinkColor.R = VISU::Storable::FindValue(theMap,"myLinkColor.R").toDouble();
501 myLinkColor.G = VISU::Storable::FindValue(theMap,"myLinkColor.G").toDouble();
502 myLinkColor.B = VISU::Storable::FindValue(theMap,"myLinkColor.B").toDouble();
508 //----------------------------------------------------------------------------
511 ::StorableEngine(SALOMEDS::SObject_ptr theSObject,
512 const Storable::TRestoringMap& theMap,
513 const std::string& thePrefix,
514 CORBA::Boolean theIsMultiFile)
516 Mesh_i* aMesh = new Mesh_i();
517 return aMesh->Restore(theSObject, theMap);
521 //----------------------------------------------------------------------------
524 ::ToStream(std::ostringstream& theStr)
526 TSuperClass::ToStream(theStr);
528 Storable::DataToStream( theStr, "myEntity", myEntity );
529 Storable::DataToStream( theStr, "mySubMeshName", mySubMeshName.c_str() );
531 Storable::DataToStream( theStr, "myPresentType", int(myPresentType) );
533 Storable::DataToStream( theStr, "my2DQuadPrsType", int(my2DQuadPrsType) );
535 Storable::DataToStream( theStr, "myIsShrank", (myIsShrank? "1":"0"));
537 Storable::DataToStream( theStr, "myCellColor.R", myCellColor.R );
538 Storable::DataToStream( theStr, "myCellColor.G", myCellColor.G );
539 Storable::DataToStream( theStr, "myCellColor.B", myCellColor.B );
541 Storable::DataToStream( theStr, "myNodeColor.R", myNodeColor.R );
542 Storable::DataToStream( theStr, "myNodeColor.G", myNodeColor.G );
543 Storable::DataToStream( theStr, "myNodeColor.B", myNodeColor.B );
545 Storable::DataToStream( theStr, "myLinkColor.R", myLinkColor.R );
546 Storable::DataToStream( theStr, "myLinkColor.G", myLinkColor.G );
547 Storable::DataToStream( theStr, "myLinkColor.B", myLinkColor.B );
551 //----------------------------------------------------------------------------
556 VISU_MeshAct* anActor = VISU_MeshAct::New();
558 VISU::Prs3d_i::CreateActor(anActor);
559 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
560 //bool toShrink = aResourceMgr->booleanValue("VISU", "mesh_shrink", false);
561 //if (toShrink) anActor->SetShrink();
562 if (anActor->IsShrunkable()) {
564 anActor->SetShrink();
568 anActor->SetFeatureEdgesAngle( aResourceMgr->doubleValue("VISU", "feature_edges_angle", 0.0) );
569 anActor->SetFeatureEdgesFlags( aResourceMgr->booleanValue("VISU", "show_feature_edges", false),
570 aResourceMgr->booleanValue("VISU", "show_boundary_edges", false),
571 aResourceMgr->booleanValue("VISU", "show_manifold_edges", false),
572 aResourceMgr->booleanValue("VISU", "show_non_manifold_edges", false) );
573 anActor->SetFeatureEdgesColoring( aResourceMgr->booleanValue("VISU", "feature_edges_coloring", false) );
575 if (myType == VISU::TGROUP )
577 anActor->SetIsDisplayNameActor( true );
578 anActor->SetNameActorText( GetSubMeshName().c_str() );
581 UpdateActor(anActor);
590 //----------------------------------------------------------------------------
593 ::UpdateActor(VISU_ActorBase* theActor)
595 if(VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(theActor)){
596 if(MYDEBUG) MESSAGE("Mesh_i::UpdateActor");
597 VISU::Prs3d_i::UpdateActor(anActor);
598 anActor->SetRepresentation(myPresentType);
599 if (anActor->IsShrunkable()) {
601 anActor->SetShrink();
605 if(my2DQuadPrsType == VISU::LINES)
606 anActor->SetQuadratic2DRepresentation(VISU_Actor::eLines);
608 anActor->SetQuadratic2DRepresentation(VISU_Actor::eArcs);
610 anActor->GetSurfaceProperty()->SetColor(myCellColor.R, myCellColor.G, myCellColor.B);
611 anActor->GetEdgeProperty()->SetColor(myLinkColor.R, myLinkColor.G, myLinkColor.B);
612 anActor->GetNodeProperty()->SetColor(myNodeColor.R, myNodeColor.G, myNodeColor.B);
616 //----------------------------------------------------------------------------
619 void VISU::Mesh_i::SetShrink(CORBA::Boolean toShrink)
621 if(toShrink == myIsShrank)
623 VISU::TSetModified aModified(this);
624 myIsShrank = toShrink;
625 myParamsTime.Modified();
628 //----------------------------------------------------------------------------
629 CORBA::Boolean VISU::Mesh_i::IsShrank()