Back to index

salome-smesh  6.5.0
SMESH_TypeFilter.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "SMESH_TypeFilter.hxx"
00024 
00025 #include <SUIT_Session.h>
00026 
00027 #include <SalomeApp_Study.h>
00028 #include <LightApp_DataOwner.h>
00029 
00030 #include <SALOMEconfig.h>
00031 #include CORBA_CLIENT_HEADER(SMESH_Gen)
00032 
00033 SMESH_TypeFilter::SMESH_TypeFilter (MeshObjectType theType)
00034 {
00035   myType = theType;
00036 }
00037 
00038 SMESH_TypeFilter::~SMESH_TypeFilter()
00039 {
00040 }
00041 
00042 bool SMESH_TypeFilter::isOk (const SUIT_DataOwner* theDataOwner) const
00043 {
00044   bool Ok = false, extractReference = true;
00045 
00046   const LightApp_DataOwner* owner =
00047     dynamic_cast<const LightApp_DataOwner*>(theDataOwner);
00048   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
00049     (SUIT_Session::session()->activeApplication()->activeStudy());
00050 
00051   if (owner && appStudy) {
00052     _PTR(Study) study = appStudy->studyDS();
00053     QString entry = owner->entry();
00054 
00055     _PTR(SObject) obj (study->FindObjectID(entry.toLatin1().data())), aRefSO;
00056     if( extractReference && obj && obj->ReferencedObject( aRefSO ) )
00057       obj = aRefSO;
00058     if (!obj) return false;
00059 
00060     _PTR(SObject) objFather = obj->GetFather();
00061     _PTR(SComponent) objComponent = obj->GetFatherComponent();
00062 
00063     if( objComponent->ComponentDataType()!="SMESH" )
00064       return false;
00065 
00066     int aLevel = obj->Depth() - objComponent->Depth();
00067 
00068     // Max level under the component is 5:
00069     //
00070     // 0    Mesh Component
00071     // 1    |- Hypotheses
00072     // 2    |  |- Regular 1D
00073     //      |- Algorithms
00074     //      |- Mesh 1
00075     //         |- * Main Shape
00076     //         |- Applied Hypotheses
00077     //         |- Applied Algorithms
00078     //         |- Submeshes on Face
00079     // 3       |  |- SubmeshFace
00080     // 4       |     |- * Face 1
00081     // 4       |     |- Applied algorithms ( selectable in Use Case Browser )
00082     // 5       |          |- Regular 1D
00083     //         |- Group Of Nodes
00084     //            |- Group 1
00085 
00086     if (aLevel <= 0)
00087       return false;
00088 
00089     switch (myType)
00090     {
00091       case HYPOTHESIS:
00092         {
00093           if      (aLevel == 2 && (objFather->Tag() == SMESH::Tag_HypothesisRoot))
00094             // hypo definition
00095             Ok = true;
00096           else if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_RefOnAppliedHypothesis))
00097             // applied global hypo
00098             Ok = true;
00099           else if (aLevel == 5 && (objFather->Tag() == SMESH::Tag_RefOnAppliedHypothesis))
00100             // applied local hypo
00101             Ok = true;
00102           break;
00103         }
00104       case ALGORITHM:
00105         {
00106           if      (aLevel == 2 && (objFather->Tag() == SMESH::Tag_AlgorithmsRoot))
00107             // algo definition
00108             Ok = true;
00109           else if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_RefOnAppliedAlgorithms))
00110             // applied global algo
00111             Ok = true;
00112           else if (aLevel == 5 && (objFather->Tag() == SMESH::Tag_RefOnAppliedAlgorithms))
00113             // applied local algo
00114             Ok = true;
00115           break;
00116         }
00117       case MESH:
00118         {
00119           if (aLevel == 1 && (obj->Tag() >= SMESH::Tag_FirstMeshRoot))
00120             Ok = true;
00121           break;
00122         }
00123       case SUBMESH:
00124         {
00125           // see SMESH_Gen_i.cxx for tag numbers
00126           if (aLevel == 3 && (objFather->Tag() >= SMESH::Tag_FirstSubMesh &&
00127                               objFather->Tag() <= SMESH::Tag_LastSubMesh))
00128             Ok = true;
00129           break;
00130         }
00131       case MESHorSUBMESH:
00132         {
00133           if (aLevel == 1 && (obj->Tag() >= SMESH::Tag_FirstMeshRoot))
00134             Ok = true; // mesh
00135           else if (aLevel == 3 && (objFather->Tag() >= SMESH::Tag_FirstSubMesh &&
00136                                    objFather->Tag() <= SMESH::Tag_LastSubMesh))
00137             Ok = true;
00138           break;
00139         }
00140       case SUBMESH_VERTEX: // Label "SubMeshes on vertexes"
00141         {
00142           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnVertex))
00143             Ok = true;
00144           break;
00145         }
00146       case SUBMESH_EDGE:
00147         {
00148           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnEdge))
00149             Ok = true;
00150           break;
00151         }
00152       case SUBMESH_FACE:
00153         {
00154           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnFace))
00155             Ok = true;
00156           break;
00157         }
00158       case SUBMESH_SOLID:
00159         {
00160           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnSolid))
00161             Ok = true;
00162           break;
00163         }
00164       case SUBMESH_COMPOUND:
00165         {
00166           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnCompound))
00167             Ok = true;
00168           break;
00169         }
00170       case GROUP:
00171         {
00172           if (aLevel == 3 && (objFather->Tag() >= SMESH::Tag_FirstGroup))
00173             Ok = true;
00174           break;
00175         }
00176       case GROUP_NODE:
00177         {
00178           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_NodeGroups))
00179             Ok = true;
00180           break;
00181         }
00182       case GROUP_EDGE:
00183         {
00184           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_EdgeGroups))
00185             Ok = true;
00186           break;
00187         }
00188       case GROUP_FACE:
00189         {
00190           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_FaceGroups))
00191             Ok = true;
00192           break;
00193         }
00194       case GROUP_VOLUME:
00195         {
00196           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_VolumeGroups))
00197             Ok = true;
00198           break;
00199         }
00200       case GROUP_0D:
00201         {
00202           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_VolumeGroups+1))
00203             Ok = true;
00204           break;
00205         }
00206       case IDSOURCE:
00207         {
00208           Ok = ( SMESH_TypeFilter(MESHorSUBMESH).isOk( theDataOwner ) ||
00209                  SMESH_TypeFilter(GROUP)        .isOk( theDataOwner ));
00210           break;
00211         }
00212     }
00213   }
00214   return Ok;
00215 }
00216 
00217 MeshObjectType SMESH_TypeFilter::type() const
00218 {
00219   return myType;
00220 }