From: admin Date: Thu, 20 Jan 2005 06:25:54 +0000 (+0000) Subject: Merge with OCC_development_01 X-Git-Tag: V2_2_0a1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=090aff07266d376ae028ae43434bdea7c0a0f9bb;p=modules%2Fsmesh.git Merge with OCC_development_01 --- diff --git a/Makefile.in b/Makefile.in index 7b95934ee..dfbd2629a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -27,6 +27,7 @@ mesh_algo_tetra.png \ mesh_angle.png \ mesh_area.png \ mesh_aspect.png \ +mesh_aspect_3d.png \ mesh_compute.png \ mesh_connectivity.png \ mesh_diagonal.png \ @@ -42,8 +43,11 @@ advanced_mesh_info.png \ standard_mesh_info.png \ mesh_init.png \ mesh_length.png \ +mesh_length_2d.png \ mesh_free_edges.png \ +mesh_free_edges_2d.png \ mesh_multi_edges.png \ +mesh_multi_edges_2d.png \ mesh_line_n.png \ mesh_line.png \ mesh_move_node.png \ @@ -95,6 +99,7 @@ mesh_smoothing.png \ mesh_renumbering_nodes.png \ mesh_renumbering_elements.png \ mesh_extrusion.png \ +mesh_extrusionpath.png \ mesh_revolution.png \ ModuleMesh.png \ mesh_unionGroups.png \ @@ -120,7 +125,9 @@ SMESHCatalog.xml \ flight_solid.brep \ mesh_pattern.png \ pattern_sample_2d.png \ -pattern_sample_3D.png +pattern_sample_3D.png \ +mesh_add.png \ +mesh_remove.png BIN_SCRIPT= \ VERSION diff --git a/adm_local/unix/make_commence.in b/adm_local/unix/make_commence.in index 43b015ee6..1a315f806 100644 --- a/adm_local/unix/make_commence.in +++ b/adm_local/unix/make_commence.in @@ -97,12 +97,6 @@ HDF5_INCLUDES=@HDF5_INCLUDES@ HDF5_LIBS=@HDF5_LIBS@ HDF5_MT_LIBS=@HDF5_MT_LIBS@ -# MED2 - -MED2_INCLUDES=@MED2_INCLUDES@ -MED2_LIBS=@MED2_LIBS@ -MED2_MT_LIBS=@MED2_MT_LIBS@ - # OpenCasCade OCC_INCLUDES=@CAS_CPPFLAGS@ @@ -251,8 +245,8 @@ ac_cxx_mutable.m4 check_mico.m4 libtool.m4 \ ac_cxx_namespaces.m4 check_omniorb.m4 pyembed.m4 \ ac_cxx_partial_specialization.m4 check_opengl.m4 python.m4 \ ac_cxx_typename.m4 check_pthreads.m4 check_cas.m4 \ -ac_cc_warnings.m4 check_qt.m4 check_med2.m4 \ -check_swig.m4 check_boost.m4 +ac_cc_warnings.m4 check_qt.m4 check_boost.m4 \ +check_swig.m4 $(top_srcdir)/aclocal.m4: $(ACLOCAL_SRC:%=@KERNEL_ROOT_DIR@/salome_adm/unix/config_files/%) cd $(top_srcdir) ; aclocal --acdir=adm_local/unix/config_files -I @KERNEL_ROOT_DIR@/salome_adm/unix/config_files diff --git a/configure.in.base b/configure.in.base index 16b6b77fa..38caec219 100644 --- a/configure.in.base +++ b/configure.in.base @@ -233,14 +233,6 @@ echo CHECK_HDF5 -echo -echo --------------------------------------------- -echo testing MED2 -echo --------------------------------------------- -echo - -CHECK_MED2 - echo echo --------------------------------------------- echo Testing OpenCascade @@ -288,7 +280,7 @@ echo --------------------------------------------- echo echo Configure -variables="cc_ok boost_ok lex_yacc_ok python_ok swig_ok threads_ok OpenGL_ok qt_ok vtk_ok hdf5_ok med2_ok omniORB_ok occ_ok doxygen_ok graphviz_ok Kernel_ok Geom_ok Med_ok" +variables="cc_ok boost_ok lex_yacc_ok python_ok swig_ok threads_ok OpenGL_ok qt_ok vtk_ok hdf5_ok omniORB_ok occ_ok doxygen_ok graphviz_ok Kernel_ok Geom_ok Med_ok" for var in $variables do diff --git a/doc/salome/tui/Makefile.in b/doc/salome/tui/Makefile.in index 8d8b65de9..fa7151e47 100644 --- a/doc/salome/tui/Makefile.in +++ b/doc/salome/tui/Makefile.in @@ -16,13 +16,28 @@ doxygen=@DOXYGEN@ @COMMENCE@ +PYTHON_SCRIPTS = \ + meshpy.py + docs: cp -fr $(srcdir)/SMESH ./INPUT; \ cd INPUT; \ sed 's|../../../share/salome|$(root_srcdir)|' ./doxyfile > ./doxyfile1; \ mv -f doxyfile1 doxyfile; \ $(doxygen) ./doxyfile; \ - cd ..; \ + mkdir py1; mkdir py2; \ + cd .. + for file in $(PYTHON_SCRIPTS) dummy; do \ + if [ $$file != "dummy" ]; then \ + cp $(root_srcdir)/src/SMESH_SWIG/$$file INPUT/py1/; \ + fi ; \ + done + cd INPUT; \ + python $(KERNEL_ROOT_DIR)/doc/salome/tui/KERNEL/pythfilter.py ./py1 ./py2; \ + sed 's|list_py_files_to_process|$(PYTHON_SCRIPTS)|' ./doxyfile_py > py2/doxyfile_py; \ + cd py2; \ + $(doxygen) ./doxyfile_py; \ + cd ../..; \ cp -fr $(srcdir)/SMESH/sources/static/*.* ./SMESH/ cp -fr $(srcdir)/SMESH/sources/ SMESH/ cp -fr $(srcdir)/SMESH/HTML/ SMESH/ diff --git a/doc/salome/tui/SMESH/doxyfile_py b/doc/salome/tui/SMESH/doxyfile_py new file mode 100755 index 000000000..8569636d5 --- /dev/null +++ b/doc/salome/tui/SMESH/doxyfile_py @@ -0,0 +1,200 @@ +# Doxyfile 1.3-rc1 + +#--------------------------------------------------------------------------- +# General configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = "SALOME - SMESH - v.2.1.0" +PROJECT_NUMBER = id#1.1 +OUTPUT_DIRECTORY = ../ +OUTPUT_LANGUAGE = English +EXTRACT_ALL = YES +EXTRACT_PRIVATE = YES +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = YES +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = NO +ALWAYS_DETAILED_SEC = YES +INLINE_INHERITED_MEMB = YES +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +INTERNAL_DOCS = YES +CASE_SENSE_NAMES = YES +SHORT_NAMES = NO +HIDE_SCOPE_NAMES = NO +VERBATIM_HEADERS = YES +SHOW_INCLUDE_FILES = YES +JAVADOC_AUTOBRIEF = YES +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = NO +INHERIT_DOCS = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = NO +DISTRIBUTE_GROUP_DOC = NO +TAB_SIZE = 5 +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ALIASES = +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 25 +OPTIMIZE_OUTPUT_FOR_C = YES +OPTIMIZE_OUTPUT_JAVA = YES +SHOW_USED_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = log.txt +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = list_py_files_to_process +FILE_PATTERNS = +RECURSIVE = NO +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = ../sources/ +INPUT_FILTER = +FILTER_SOURCE_FILES = YES +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = NO +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = ../SMESH/meshpy_doc +HTML_FILE_EXTENSION = .html +HTML_HEADER = ../sources/myheader_py2.html +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = YES +TOC_EXPAND = YES +DISABLE_INDEX = YES +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = YES +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_SCHEMA = +XML_DTD = +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = NO +#--------------------------------------------------------------------------- +# Configuration::addtions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = NO +HAVE_DOT = YES +CLASS_GRAPH = YES +COLLABORATION_GRAPH = NO +TEMPLATE_RELATIONS = YES +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DOT_IMAGE_FORMAT = jpg +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1200 +GENERATE_LEGEND = NO +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::addtions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO +CGI_NAME = search.cgi +CGI_URL = +DOC_URL = +DOC_ABSPATH = +BIN_ABSPATH = /usr/local/bin/ +EXT_DOC_PATHS = diff --git a/doc/salome/tui/SMESH/sources/myheader_py2.html b/doc/salome/tui/SMESH/sources/myheader_py2.html new file mode 100755 index 000000000..372b2247f --- /dev/null +++ b/doc/salome/tui/SMESH/sources/myheader_py2.html @@ -0,0 +1,24 @@ + + + + + + Main Page + + + +  +
+ + + + + + +
+
+
+ + + + diff --git a/doc/salome/tui/SMESH/sources/static/tree.js b/doc/salome/tui/SMESH/sources/static/tree.js index e1c95ec93..b2a9953b2 100755 --- a/doc/salome/tui/SMESH/sources/static/tree.js +++ b/doc/salome/tui/SMESH/sources/static/tree.js @@ -18,5 +18,12 @@ aux1 = insFld(foldersTree, gFld("TUI Reference Guide", "")) aux1 = insFld(foldersTree, gFld("IDL/Python mapping", "")) insDoc(aux1, gLnk("Mapping of SMESH IDL definitions to Python language", "", "page2.html")) + +aux1 = insFld(foldersTree, gFld("Python Commands", "", "meshpy_doc/main.html")) + insDoc(aux1, gLnk("Package List", "", "meshpy_doc/namespaces.html")) + insDoc(aux1, gLnk("Data Structures", "", "meshpy_doc/annotated.html")) + insDoc(aux1, gLnk("Namespace Members", "", "meshpy_doc/namespacemembers.html")) + insDoc(aux1, gLnk("File List", "", "meshpy_doc/files.html")) + aux1 = insFld(foldersTree, gFld("Adding meshers in SMESH", "")) insDoc(aux1, gLnk("Using Plugin mechanism in SMESH", "", "PluginMeshers.html")) diff --git a/idl/SMESH_Filter.idl b/idl/SMESH_Filter.idl index d1f0c3d9f..c66a90ea0 100644 --- a/idl/SMESH_Filter.idl +++ b/idl/SMESH_Filter.idl @@ -1,379 +1,423 @@ -// 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 : SMESH_Filter.idl -// Author : Alexey Petrov, OCC - -#ifndef _SMESH_FILTER_IDL_ -#define _SMESH_FILTER_IDL_ - -#include "SALOME_Exception.idl" -#include "SALOME_GenericObj.idl" -#include "SMESH_Mesh.idl" - - -module GEOM -{ - interface GEOM_Object; -}; - - -module SMESH -{ - - /*! - * Enumeration of functor types - */ - enum FunctorType - { - FT_AspectRatio, - FT_Warping, - FT_MinimumAngle, - FT_Taper, - FT_Skew, - FT_Area, - FT_FreeBorders, - FT_FreeEdges, - FT_MultiConnection, - FT_Length, - FT_BelongToGeom, - FT_BelongToPlane, - FT_BelongToCylinder, - FT_RangeOfIds, - FT_LessThan, - FT_MoreThan, - FT_EqualTo, - FT_LogicalNOT, - FT_LogicalAND, - FT_LogicalOR, - FT_Undefined - }; - - /*! - * Base interface for all functors ( i.e. numerical functors and predicates ) - */ - interface Functor: SALOME::GenericObj - { - void SetMesh( in SMESH_Mesh theMesh ); - FunctorType GetFunctorType(); - ElementType GetElementType(); - }; - - - - /*! - * Numerical functors are intended for calculating value by Id of mesh entity - */ - interface NumericalFunctor: Functor - { - double GetValue( in long theElementId ); - - /*! - * Set precision for calculation. It is a position after point which is - * used to functor value after calculation. - */ - void SetPrecision( in long thePrecision ); - long GetPrecision(); - }; - interface MinimumAngle : NumericalFunctor{}; - interface AspectRatio : NumericalFunctor{}; - interface Warping : NumericalFunctor{}; - interface Taper : NumericalFunctor{}; - interface Skew : NumericalFunctor{}; - interface Area : NumericalFunctor{}; - interface Length : NumericalFunctor{}; - interface MultiConnection : NumericalFunctor{}; - - /*! - * Predicates are intended for verification of criteria, - * must return bool value by mesh id - */ - interface Predicate: Functor - { - boolean IsSatisfy( in long thEntityId ); - }; - - /*! - * Logical functor (predicate) "Belong To Geometry". - * Verify whether mesh element or node belong to pointed Geom Object - */ - interface BelongToGeom: Predicate - { - void SetGeom( in GEOM::GEOM_Object theGeom ); - void SetElementType( in ElementType theType ); - - void SetShapeName( in string theName ); - string GetShapeName(); - }; - - /*! - * Logical functor (predicate) "Belong To Surface". - * Base interface for "belong to plane" and "belong to cylinder interfaces" - */ - interface BelongToSurface: Predicate - { - void SetTolerance( in double theToler ); - double GetTolerance(); - void SetShapeName( in string theName, in ElementType theType ); - string GetShapeName(); - }; - - - /*! - * Logical functor (predicate) "Belong To Plane". - * Verify whether mesh element lie in pointed Geom planar object - */ - interface BelongToPlane: BelongToSurface - { - void SetPlane( in GEOM::GEOM_Object theGeom, in ElementType theType ); - }; - - /*! - * Logical functor (predicate) "Belong To Culinder". - * Verify whether mesh element lie in pointed Geom cylindrical object - */ - interface BelongToCylinder: BelongToSurface - { - void SetCylinder( in GEOM::GEOM_Object theGeom, in ElementType theType ); - }; - - /*! - * Logical functor (predicate) "Free borders". - * Verify whether 1D mesh element is free ( i.e. connected to one face only ) - */ - interface FreeBorders: Predicate{}; - - /*! - * Logical functor (predicate) "Free edges". - * Verify whether 2D mesh element has free edges( i.e. edges connected to one face only ) - */ - interface FreeEdges: Predicate - - { - struct Border - { - long myElemId; - long myPnt1, myPnt2; - }; - typedef sequence Borders; - Borders GetBorders(); - }; - - - /*! - * Abstract logical functor (predicate) "RangeOfIds". - * Verify whether an Entity Id belongs to defined sequence of id's - */ - interface RangeOfIds: Predicate - { - void SetRange( in long_array theIds ); - boolean SetRangeStr( in string theRange ); - string GetRangeStr(); - - void SetElementType( in ElementType theType ); - }; - - /*! - * Comparator. Predicate for compare value calculated - * by numerical functor with threshold value - */ - interface Comparator: Predicate - { - void SetMargin( in double theValue ); - void SetNumFunctor( in NumericalFunctor theFunct ); - double GetMargin(); - }; - interface LessThan: Comparator{}; - interface MoreThan: Comparator{}; - interface EqualTo : Comparator - { - void SetTolerance( in double theToler ); - double GetTolerance(); - }; - - /*! - * Logical predicates are intended for compose predicates using boolean operations - */ - interface Logical: Predicate{}; - - interface LogicalNOT: Logical - { - void SetPredicate(in Predicate thePredicate); - }; - - interface LogicalBinary: Logical -{ - void SetPredicate1( in Predicate thePredicate ); - void SetPredicate2( in Predicate thePredicate ); - }; - - interface LogicalAND: LogicalBinary{}; - interface LogicalOR : LogicalBinary{}; - - /*! - * Filter - */ - interface Filter: SALOME::GenericObj - { - /*! - * Structure containing information about one criterion - * Type - FT_Taper, FT_Skew ... - * Compare - FT_LessThan, FT_MoreThan, FT_EqualTo - * Threshold - threshold value - * UnaryOp - unary logical operation: FT_LogicalNOT or FT_Undefined - * BinaryOp - binary logical operation FT_LogicalAND, FT_LogicalOR or - * (FT_Undefined must be for the last criterion) - * ThresholdStr - Threshold value defined as string. Used for: - * 1. Diaposon of identifiers. Example: "1,2,3,5-10,12,27-29" - * 2. BelongToGeom predicate for storing name of shape - * Tolerance - Tolerance is used for comparators (EqualTo comparision) and for - * "Belong to plane" and "Belong to cylinder" predicates - * TypeOfElement - type of element SMESH::NODE, SMESH::FACE (used by BelongToGeom predicate only) - * Precision - Precision of numerical functors - */ - struct Criterion - { - long Type; - long Compare; - double Threshold; - string ThresholdStr; - long UnaryOp; - long BinaryOp; - double Tolerance; - ElementType TypeOfElement; - long Precision; - }; - - typedef sequence Criteria; - - void SetPredicate( in Predicate thePredicate ); - long_array GetElementsId( in SMESH_Mesh theMesh ); - ElementType GetElementType(); - Predicate GetPredicate(); - - boolean GetCriteria( out Criteria theCriteria ); - boolean SetCriteria( in Criteria theCriteria ); - }; - - - /*! - * Interface for working with library of filters - */ - interface FilterLibrary : SALOME::GenericObj - { - /*! - * Copy filter from library by name (new filter is created) - */ - Filter Copy( in string theFilterName ); - - /*! - * Methods for editing library - */ - boolean Add ( in string theFilterName, in Filter theFilter ); - boolean AddEmpty( in string theFilterName, in ElementType theType ); // add empty filter - boolean Delete ( in string theFilterName ); - boolean Replace ( in string theFilterName, in string theNewName, in Filter theFilter ); - - /*! - * Save library on disk - */ - boolean Save(); - boolean SaveAs( in string aFileName ); - - /*! - * Query methods - */ - boolean IsPresent( in string aFilterName ); - long NbFilters( in ElementType aType ); - string_array GetNames( in ElementType aType ); - string_array GetAllNames(); - void SetFileName( in string aFilterName ); - string GetFileName(); - }; - - - /*! - * Interface of Filter manager - */ - interface FilterManager: SALOME::GenericObj - { - /*! - * Create numerical functors - */ - MinimumAngle CreateMinimumAngle(); - AspectRatio CreateAspectRatio(); - Warping CreateWarping(); - Taper CreateTaper(); - Skew CreateSkew(); - Area CreateArea(); - Length CreateLength(); - MultiConnection CreateMultiConnection(); - - /*! - * Create logical functors ( predicates ) - */ - BelongToGeom CreateBelongToGeom(); - BelongToPlane CreateBelongToPlane(); - BelongToCylinder CreateBelongToCylinder(); - - FreeBorders CreateFreeBorders(); - FreeEdges CreateFreeEdges(); - - RangeOfIds CreateRangeOfIds(); - - /*! - * Create comparators ( predicates ) - */ - LessThan CreateLessThan(); - MoreThan CreateMoreThan(); - EqualTo CreateEqualTo(); - - /*! - * Create boolean operations ( predicates ) - */ - LogicalNOT CreateLogicalNOT(); - LogicalAND CreateLogicalAND(); - LogicalOR CreateLogicalOR(); - - /*! - * Create filter - */ - Filter CreateFilter(); - - /*! - * Load filter library. If libary does not exist it is created - */ - FilterLibrary LoadLibrary( in string aFileName ); - - /*! - * Create new library - */ - FilterLibrary CreateLibrary(); - - /*! - * Delete library - */ - boolean DeleteLibrary( in string aFileName ); - }; -}; - - -#endif +// 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 : SMESH_Filter.idl +// Author : Alexey Petrov, OCC + +#ifndef _SMESH_FILTER_IDL_ +#define _SMESH_FILTER_IDL_ + +#include "SALOME_Exception.idl" +#include "SALOME_GenericObj.idl" +#include "SMESH_Mesh.idl" + + +module GEOM +{ + interface GEOM_Object; +}; + + +module SMESH +{ + + /*! + * Enumeration of functor types + */ + enum FunctorType + { + FT_AspectRatio, + FT_AspectRatio3D, + FT_Warping, + FT_MinimumAngle, + FT_Taper, + FT_Skew, + FT_Area, + FT_FreeBorders, + FT_FreeEdges, + FT_MultiConnection, + FT_MultiConnection2D, + FT_Length, + FT_Length2D, + FT_BelongToGeom, + FT_BelongToPlane, + FT_BelongToCylinder, + FT_LyingOnGeom, + FT_RangeOfIds, + FT_LessThan, + FT_MoreThan, + FT_EqualTo, + FT_LogicalNOT, + FT_LogicalAND, + FT_LogicalOR, + FT_Undefined + }; + + /*! + * Base interface for all functors ( i.e. numerical functors and predicates ) + */ + interface Functor: SALOME::GenericObj + { + void SetMesh( in SMESH_Mesh theMesh ); + FunctorType GetFunctorType(); + ElementType GetElementType(); + }; + + + + /*! + * Numerical functors are intended for calculating value by Id of mesh entity + */ + interface NumericalFunctor: Functor + { + double GetValue( in long theElementId ); + + /*! + * Set precision for calculation. It is a position after point which is + * used to functor value after calculation. + */ + void SetPrecision( in long thePrecision ); + long GetPrecision(); + }; + interface MinimumAngle : NumericalFunctor{}; + interface AspectRatio : NumericalFunctor{}; + interface AspectRatio3D : NumericalFunctor{}; + interface Warping : NumericalFunctor{}; + interface Taper : NumericalFunctor{}; + interface Skew : NumericalFunctor{}; + interface Area : NumericalFunctor{}; + interface Length : NumericalFunctor{}; + interface Length2D : NumericalFunctor + { + struct Value + { + double myLength; + long myPnt1, myPnt2; + }; + typedef sequence Values; + Values GetValues(); + }; + interface MultiConnection : NumericalFunctor{}; + interface MultiConnection2D : NumericalFunctor + { + struct Value + { + long myNbConnects; + long myPnt1, myPnt2; + }; + + typedef sequence Values; + Values GetValues(); + }; + + /*! + * Predicates are intended for verification of criteria, + * must return bool value by mesh id + */ + interface Predicate: Functor + { + boolean IsSatisfy( in long thEntityId ); + }; + + /*! + * Logical functor (predicate) "Belong To Geometry". + * Verify whether mesh element or node belong to pointed Geom Object + */ + interface BelongToGeom: Predicate + { + void SetGeom( in GEOM::GEOM_Object theGeom ); + void SetElementType( in ElementType theType ); + + void SetShapeName( in string theName ); + string GetShapeName(); + }; + + /*! + * Logical functor (predicate) "Belong To Surface". + * Base interface for "belong to plane" and "belong to cylinder interfaces" + */ + interface BelongToSurface: Predicate + { + void SetTolerance( in double theToler ); + double GetTolerance(); + void SetShapeName( in string theName, in ElementType theType ); + string GetShapeName(); + }; + + + /*! + * Logical functor (predicate) "Belong To Plane". + * Verify whether mesh element lie in pointed Geom planar object + */ + interface BelongToPlane: BelongToSurface + { + void SetPlane( in GEOM::GEOM_Object theGeom, in ElementType theType ); + }; + + /*! + * Logical functor (predicate) "Belong To Culinder". + * Verify whether mesh element lie in pointed Geom cylindrical object + */ + interface BelongToCylinder: BelongToSurface + { + void SetCylinder( in GEOM::GEOM_Object theGeom, in ElementType theType ); + }; + + /*! + * Logical functor (predicate) "Lying On Geometry". + * Verify whether mesh element or node lying or partially lying on the pointed Geom Object + */ + interface LyingOnGeom: Predicate + { + void SetGeom( in GEOM::GEOM_Object theGeom ); + void SetElementType( in ElementType theType ); + + void SetShapeName( in string theName ); + string GetShapeName(); + }; + + /*! + * Logical functor (predicate) "Free borders". + * Verify whether 1D mesh element is free ( i.e. connected to one face only ) + */ + interface FreeBorders: Predicate{}; + + /*! + * Logical functor (predicate) "Free edges". + * Verify whether 2D mesh element has free edges( i.e. edges connected to one face only ) + */ + interface FreeEdges: Predicate + + { + struct Border + { + long myElemId; + long myPnt1, myPnt2; + }; + typedef sequence Borders; + Borders GetBorders(); + }; + + + /*! + * Abstract logical functor (predicate) "RangeOfIds". + * Verify whether an Entity Id belongs to defined sequence of id's + */ + interface RangeOfIds: Predicate + { + void SetRange( in long_array theIds ); + boolean SetRangeStr( in string theRange ); + string GetRangeStr(); + + void SetElementType( in ElementType theType ); + }; + + /*! + * Comparator. Predicate for compare value calculated + * by numerical functor with threshold value + */ + interface Comparator: Predicate + { + void SetMargin( in double theValue ); + void SetNumFunctor( in NumericalFunctor theFunct ); + double GetMargin(); + }; + interface LessThan: Comparator{}; + interface MoreThan: Comparator{}; + interface EqualTo : Comparator + { + void SetTolerance( in double theToler ); + double GetTolerance(); + }; + + /*! + * Logical predicates are intended for compose predicates using boolean operations + */ + interface Logical: Predicate{}; + + interface LogicalNOT: Logical + { + void SetPredicate(in Predicate thePredicate); + }; + + interface LogicalBinary: Logical +{ + void SetPredicate1( in Predicate thePredicate ); + void SetPredicate2( in Predicate thePredicate ); + }; + + interface LogicalAND: LogicalBinary{}; + interface LogicalOR : LogicalBinary{}; + + /*! + * Filter + */ + interface Filter: SALOME::GenericObj + { + /*! + * Structure containing information about one criterion + * Type - FT_Taper, FT_Skew ... + * Compare - FT_LessThan, FT_MoreThan, FT_EqualTo + * Threshold - threshold value + * UnaryOp - unary logical operation: FT_LogicalNOT or FT_Undefined + * BinaryOp - binary logical operation FT_LogicalAND, FT_LogicalOR or + * (FT_Undefined must be for the last criterion) + * ThresholdStr - Threshold value defined as string. Used for: + * 1. Diaposon of identifiers. Example: "1,2,3,5-10,12,27-29" + * 2. BelongToGeom predicate for storing name of shape + * Tolerance - Tolerance is used for comparators (EqualTo comparision) and for + * "Belong to plane" and "Belong to cylinder" predicates + * TypeOfElement - type of element SMESH::NODE, SMESH::FACE (used by BelongToGeom predicate only) + * Precision - Precision of numerical functors + */ + struct Criterion + { + long Type; + long Compare; + double Threshold; + string ThresholdStr; + long UnaryOp; + long BinaryOp; + double Tolerance; + ElementType TypeOfElement; + long Precision; + }; + + typedef sequence Criteria; + + void SetPredicate( in Predicate thePredicate ); + long_array GetElementsId( in SMESH_Mesh theMesh ); + ElementType GetElementType(); + Predicate GetPredicate(); + + boolean GetCriteria( out Criteria theCriteria ); + boolean SetCriteria( in Criteria theCriteria ); + }; + + + /*! + * Interface for working with library of filters + */ + interface FilterLibrary : SALOME::GenericObj + { + /*! + * Copy filter from library by name (new filter is created) + */ + Filter Copy( in string theFilterName ); + + /*! + * Methods for editing library + */ + boolean Add ( in string theFilterName, in Filter theFilter ); + boolean AddEmpty( in string theFilterName, in ElementType theType ); // add empty filter + boolean Delete ( in string theFilterName ); + boolean Replace ( in string theFilterName, in string theNewName, in Filter theFilter ); + + /*! + * Save library on disk + */ + boolean Save(); + boolean SaveAs( in string aFileName ); + + /*! + * Query methods + */ + boolean IsPresent( in string aFilterName ); + long NbFilters( in ElementType aType ); + string_array GetNames( in ElementType aType ); + string_array GetAllNames(); + void SetFileName( in string aFilterName ); + string GetFileName(); + }; + + + /*! + * Interface of Filter manager + */ + interface FilterManager: SALOME::GenericObj + { + /*! + * Create numerical functors + */ + MinimumAngle CreateMinimumAngle(); + AspectRatio CreateAspectRatio(); + AspectRatio3D CreateAspectRatio3D(); + Warping CreateWarping(); + Taper CreateTaper(); + Skew CreateSkew(); + Area CreateArea(); + Length CreateLength(); + Length2D CreateLength2D(); + MultiConnection CreateMultiConnection(); + MultiConnection2D CreateMultiConnection2D(); + + /*! + * Create logical functors ( predicates ) + */ + BelongToGeom CreateBelongToGeom(); + BelongToPlane CreateBelongToPlane(); + BelongToCylinder CreateBelongToCylinder(); + + LyingOnGeom CreateLyingOnGeom(); + + FreeBorders CreateFreeBorders(); + FreeEdges CreateFreeEdges(); + + RangeOfIds CreateRangeOfIds(); + + /*! + * Create comparators ( predicates ) + */ + LessThan CreateLessThan(); + MoreThan CreateMoreThan(); + EqualTo CreateEqualTo(); + + /*! + * Create boolean operations ( predicates ) + */ + LogicalNOT CreateLogicalNOT(); + LogicalAND CreateLogicalAND(); + LogicalOR CreateLogicalOR(); + + /*! + * Create filter + */ + Filter CreateFilter(); + + /*! + * Load filter library. If libary does not exist it is created + */ + FilterLibrary LoadLibrary( in string aFileName ); + + /*! + * Create new library + */ + FilterLibrary CreateLibrary(); + + /*! + * Delete library + */ + boolean DeleteLibrary( in string aFileName ); + }; +}; + + +#endif diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index d64d9389f..77d9d186e 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -132,6 +132,15 @@ module SMESH DRS_FAIL // general failure (exception etc.) }; + /*! + * Enumeration for DriverMED (used by Perform() method) + */ + enum MED_VERSION // in the order of severity + { + MED_V2_1, + MED_V2_2 + }; + typedef sequence log_array; @@ -315,12 +324,18 @@ module SMESH raises (SALOME::SALOME_Exception); /*! - * Export Mesh with DAT and MED Formats + * Export Mesh to MED Formats */ - void ExportDAT( in string file ) + void ExportToMED( in string file, in boolean auto_groups, in MED_VERSION theVersion ) raises (SALOME::SALOME_Exception); void ExportMED( in string file, in boolean auto_groups ) raises (SALOME::SALOME_Exception); + + /*! + * Export Mesh to DAT, UNV and STL Formats + */ + void ExportDAT( in string file ) + raises (SALOME::SALOME_Exception); void ExportUNV( in string file ) raises (SALOME::SALOME_Exception); void ExportSTL( in string file, in boolean isascii ) @@ -335,6 +350,9 @@ module SMESH long NbNodes() raises (SALOME::SALOME_Exception); + long NbElements() + raises (SALOME::SALOME_Exception); + long NbEdges() raises (SALOME::SALOME_Exception); @@ -365,6 +383,15 @@ module SMESH long NbSubMesh() raises (SALOME::SALOME_Exception); + long_array GetElementsId() + raises (SALOME::SALOME_Exception); + + long_array GetElementsByType( in ElementType theType ) + raises (SALOME::SALOME_Exception); + + long_array GetNodesId() + raises (SALOME::SALOME_Exception); + string Dump(); }; @@ -508,6 +535,24 @@ module SMESH in DirStruct StepVector, in long NbOfSteps); + void ExtrusionAlongPath(in long_array IDsOfElements, + in SMESH_Mesh PathMesh, + in GEOM::GEOM_Object PathShape, + in long NodeStart, + in boolean HasAngles, + in double_array Angles, + in boolean HasRefPoint, + in PointStruct RefPoint); + + void ExtrusionAlongPathObject(in SMESH_IDSource theObject, + in SMESH_Mesh PathMesh, + in GEOM::GEOM_Object PathShape, + in long NodeStart, + in boolean HasAngles, + in double_array Angles, + in boolean HasRefPoint, + in PointStruct RefPoint); + enum MirrorType { POINT, AXIS, PLANE }; void Mirror (in long_array IDsOfElements, diff --git a/idl/SMESH_Pattern.idl b/idl/SMESH_Pattern.idl index 1b626ad5e..f02fe4326 100644 --- a/idl/SMESH_Pattern.idl +++ b/idl/SMESH_Pattern.idl @@ -79,6 +79,28 @@ module SMESH in GEOM::GEOM_Object theVertex000, in GEOM::GEOM_Object theVertex001); + /*! + * Compute nodes coordinates applying + * the loaded pattern to mesh faces. The first key-point + * will be mapped into -th node of each face + */ + point_array ApplyToMeshFaces(in SMESH_Mesh theMesh, + in long_array theFacesIDs, + in long theNodeIndexOnKeyPoint1, + in boolean theReverse); + + /*! + * Compute nodes coordinates applying + * the loaded pattern to hexahedrons. The (0,0,0) key-point + * will be mapped into -th node of each volume. + * The (0,0,1) key-point will be mapped into -th + * node of each volume. + */ + point_array ApplyToHexahedrons(in SMESH_Mesh theMesh, + in long_array theVolumesIDs, + in long theNode000Index, + in long theNode001Index); + /*! * Create nodes and elements in using nodes * coordinates computed by either of Apply...() methods diff --git a/resources/SMESH_en.xml b/resources/SMESH_en.xml index b574a7f2f..0bbbc4597 100644 --- a/resources/SMESH_en.xml +++ b/resources/SMESH_en.xml @@ -73,16 +73,21 @@ + - - - + + + + + - + + + @@ -122,6 +127,7 @@ + @@ -129,7 +135,7 @@ - + @@ -145,7 +151,11 @@ - + + + + + @@ -230,23 +240,36 @@ + + + + + + + + - - - - + + + + + + + + + - + - + @@ -272,23 +295,36 @@ + + + + + + + + - - - - + + + + + + + + + - + - + @@ -316,23 +352,36 @@ + + + + + + + + - - - - + + + + + + + + + - + - + @@ -370,15 +419,20 @@ - - - + + + + + + - + + + @@ -411,6 +465,7 @@ + diff --git a/resources/mesh_add.png b/resources/mesh_add.png new file mode 100755 index 000000000..2dde69a72 Binary files /dev/null and b/resources/mesh_add.png differ diff --git a/resources/mesh_aspect_3d.png b/resources/mesh_aspect_3d.png new file mode 100644 index 000000000..479263444 Binary files /dev/null and b/resources/mesh_aspect_3d.png differ diff --git a/resources/mesh_extrusionpath.png b/resources/mesh_extrusionpath.png new file mode 100644 index 000000000..47f0aa76a Binary files /dev/null and b/resources/mesh_extrusionpath.png differ diff --git a/resources/mesh_free_edges_2d.png b/resources/mesh_free_edges_2d.png new file mode 100644 index 000000000..cc6cdb8ad Binary files /dev/null and b/resources/mesh_free_edges_2d.png differ diff --git a/resources/mesh_length_2d.png b/resources/mesh_length_2d.png new file mode 100644 index 000000000..0009dc0cc Binary files /dev/null and b/resources/mesh_length_2d.png differ diff --git a/resources/mesh_multi_edges_2d.png b/resources/mesh_multi_edges_2d.png new file mode 100644 index 000000000..627ceebbf Binary files /dev/null and b/resources/mesh_multi_edges_2d.png differ diff --git a/resources/mesh_remove.png b/resources/mesh_remove.png new file mode 100755 index 000000000..960f1ac00 Binary files /dev/null and b/resources/mesh_remove.png differ diff --git a/src/Controls/Makefile.in b/src/Controls/Makefile.in index 556958d66..2a862b834 100644 --- a/src/Controls/Makefile.in +++ b/src/Controls/Makefile.in @@ -31,7 +31,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl:$(top_builddir)/idl @COMMENCE@ -EXPORT_HEADERS = SMESH_Controls.hxx +EXPORT_HEADERS = SMESH_Controls.hxx SMESH_ControlsDef.hxx # Libraries targets diff --git a/src/Controls/SMESHControls.cxx b/src/Controls/SMESHControls.cxx index 10ecd711a..0c8d145a3 100644 --- a/src/Controls/SMESHControls.cxx +++ b/src/Controls/SMESHControls.cxx @@ -17,7 +17,7 @@ // // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -#include "SMESH_Controls.hxx" +#include "SMESH_ControlsDef.hxx" int main(int argc, char** argv) { @@ -29,7 +29,9 @@ int main(int argc, char** argv) new Skew(); new Area(); new Length(); + // new Length2D(); new MultiConnection(); + // new MultiConnection2D(); new FreeBorders(); new LessThan(); new MoreThan(); diff --git a/src/Controls/SMESH_Controls.cxx b/src/Controls/SMESH_Controls.cxx index a0dd64e13..2bf885a7a 100644 --- a/src/Controls/SMESH_Controls.cxx +++ b/src/Controls/SMESH_Controls.cxx @@ -17,7 +17,7 @@ // // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -#include "SMESH_Controls.hxx" +#include "SMESH_ControlsDef.hxx" #include @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -48,78 +47,79 @@ #include "SMDS_MeshNode.hxx" - /* AUXILIARY METHODS */ -static inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 ) -{ - gp_Vec v1( P1 - P2 ), v2( P3 - P2 ); - - return v1.Magnitude() < gp::Resolution() || - v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 ); -} - -static inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 ) -{ - gp_Vec aVec1( P2 - P1 ); - gp_Vec aVec2( P3 - P1 ); - return ( aVec1 ^ aVec2 ).Magnitude() * 0.5; -} - -static inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 ) -{ - return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() ); -} +namespace{ + inline double getAngle( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 ) + { + gp_Vec v1( P1 - P2 ), v2( P3 - P2 ); + + return v1.Magnitude() < gp::Resolution() || + v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 ); + } -static inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 ) -{ - double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) ); - return aDist; -} + inline double getArea( const gp_XYZ& P1, const gp_XYZ& P2, const gp_XYZ& P3 ) + { + gp_Vec aVec1( P2 - P1 ); + gp_Vec aVec2( P3 - P1 ); + return ( aVec1 ^ aVec2 ).Magnitude() * 0.5; + } -static int getNbMultiConnection( SMDS_Mesh* theMesh, const int theId ) -{ - if ( theMesh == 0 ) - return 0; + inline double getArea( const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3 ) + { + return getArea( P1.XYZ(), P2.XYZ(), P3.XYZ() ); + } - const SMDS_MeshElement* anEdge = theMesh->FindElement( theId ); - if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge || anEdge->NbNodes() != 2 ) - return 0; - TColStd_MapOfInteger aMap; - int aResult = 0; - SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator(); - if ( anIter != 0 ) + inline double getDistance( const gp_XYZ& P1, const gp_XYZ& P2 ) { - while( anIter->more() ) - { - const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next(); - if ( aNode == 0 ) - return 0; - SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator(); - while( anElemIter->more() ) - { - const SMDS_MeshElement* anElem = anElemIter->next(); - if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) - { - int anId = anElem->GetID(); + double aDist = gp_Pnt( P1 ).Distance( gp_Pnt( P2 ) ); + return aDist; + } - if ( anIter->more() ) // i.e. first node - aMap.Add( anId ); - else if ( aMap.Contains( anId ) ) - aResult++; - } + int getNbMultiConnection( SMDS_Mesh* theMesh, const int theId ) + { + if ( theMesh == 0 ) + return 0; + + const SMDS_MeshElement* anEdge = theMesh->FindElement( theId ); + if ( anEdge == 0 || anEdge->GetType() != SMDSAbs_Edge || anEdge->NbNodes() != 2 ) + return 0; + + TColStd_MapOfInteger aMap; + + int aResult = 0; + SMDS_ElemIteratorPtr anIter = anEdge->nodesIterator(); + if ( anIter != 0 ) { + while( anIter->more() ) { + const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next(); + if ( aNode == 0 ) + return 0; + SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator(); + while( anElemIter->more() ) { + const SMDS_MeshElement* anElem = anElemIter->next(); + if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) { + int anId = anElem->GetID(); + + if ( anIter->more() ) // i.e. first node + aMap.Add( anId ); + else if ( aMap.Contains( anId ) ) + aResult++; + } + } } } + + return aResult; } - return aResult; } + using namespace SMESH::Controls; /* @@ -141,10 +141,10 @@ void NumericalFunctor::SetMesh( SMDS_Mesh* theMesh ) myMesh = theMesh; } -bool NumericalFunctor::GetPoints(const int theId, - TColgp_SequenceOfXYZ& theRes ) const +bool NumericalFunctor::GetPoints(const int theId, + TSequenceOfXYZ& theRes ) const { - theRes.Clear(); + theRes.clear(); if ( myMesh == 0 ) return false; @@ -153,9 +153,9 @@ bool NumericalFunctor::GetPoints(const int theId, } bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem, - TColgp_SequenceOfXYZ& theRes ) + TSequenceOfXYZ& theRes ) { - theRes.Clear(); + theRes.clear(); if ( anElem == 0) return false; @@ -167,8 +167,9 @@ bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem, while( anIter->more() ) { const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next(); - if ( aNode != 0 ) - theRes.Append( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) ); + if ( aNode != 0 ){ + theRes.push_back( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) ); + } } } @@ -187,7 +188,7 @@ void NumericalFunctor::SetPrecision( const long thePrecision ) double NumericalFunctor::GetValue( long theId ) { - TColgp_SequenceOfXYZ P; + TSequenceOfXYZ P; if ( GetPoints( theId, P )) { double aVal = GetValue( P ); @@ -196,7 +197,6 @@ double NumericalFunctor::GetValue( long theId ) double prec = pow( 10., (double)( myPrecision ) ); aVal = floor( aVal * prec + 0.5 ) / prec; } - return aVal; } @@ -208,11 +208,11 @@ double NumericalFunctor::GetValue( long theId ) Description : Functor for calculation of minimum angle */ -double MinimumAngle::GetValue( const TColgp_SequenceOfXYZ& P ) +double MinimumAngle::GetValue( const TSequenceOfXYZ& P ) { double aMin; - if ( P.Length() == 3 ) + if ( P.size() == 3 ) { double A0 = getAngle( P( 3 ), P( 1 ), P( 2 ) ); double A1 = getAngle( P( 1 ), P( 2 ), P( 3 ) ); @@ -220,7 +220,7 @@ double MinimumAngle::GetValue( const TColgp_SequenceOfXYZ& P ) aMin = Min( A0, Min( A1, A2 ) ); } - else if ( P.Length() == 4 ) + else if ( P.size() == 4 ) { double A0 = getAngle( P( 4 ), P( 1 ), P( 2 ) ); double A1 = getAngle( P( 1 ), P( 2 ), P( 3 ) ); @@ -251,9 +251,9 @@ SMDSAbs_ElementType MinimumAngle::GetType() const Class : AspectRatio Description : Functor for calculating aspect ratio */ -double AspectRatio::GetValue( const TColgp_SequenceOfXYZ& P ) +double AspectRatio::GetValue( const TSequenceOfXYZ& P ) { - int nbNodes = P.Length(); + int nbNodes = P.size(); if ( nbNodes != 3 && nbNodes != 4 ) return 0; @@ -306,65 +306,81 @@ SMDSAbs_ElementType AspectRatio::GetType() const Class : AspectRatio3D Description : Functor for calculating aspect ratio */ +namespace{ -static inline double getHalfPerimeter(double theTria[3]){ - return (theTria[0] + theTria[1] + theTria[2])/2.0; -} + inline double getHalfPerimeter(double theTria[3]){ + return (theTria[0] + theTria[1] + theTria[2])/2.0; + } -static inline double getArea(double theHalfPerim, double theTria[3]){ - return sqrt(theHalfPerim* - (theHalfPerim-theTria[0])* - (theHalfPerim-theTria[1])* - (theHalfPerim-theTria[2])); -} + inline double getArea(double theHalfPerim, double theTria[3]){ + return sqrt(theHalfPerim* + (theHalfPerim-theTria[0])* + (theHalfPerim-theTria[1])* + (theHalfPerim-theTria[2])); + } -static inline double getVolume(double theLen[6]){ - double a2 = theLen[0]*theLen[0]; - double b2 = theLen[1]*theLen[1]; - double c2 = theLen[2]*theLen[2]; - double d2 = theLen[3]*theLen[3]; - double e2 = theLen[4]*theLen[4]; - double f2 = theLen[5]*theLen[5]; - double P = 4.0*a2*b2*d2; - double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2); - double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2); - return sqrt(P-Q+R)/12.0; -} + inline double getVolume(double theLen[6]){ + double a2 = theLen[0]*theLen[0]; + double b2 = theLen[1]*theLen[1]; + double c2 = theLen[2]*theLen[2]; + double d2 = theLen[3]*theLen[3]; + double e2 = theLen[4]*theLen[4]; + double f2 = theLen[5]*theLen[5]; + double P = 4.0*a2*b2*d2; + double Q = a2*(b2+d2-e2)-b2*(a2+d2-f2)-d2*(a2+b2-c2); + double R = (b2+d2-e2)*(a2+d2-f2)*(a2+d2-f2); + return sqrt(P-Q+R)/12.0; + } -static inline double getHeight( const gp_Pnt& P1, const gp_Pnt& P2, - const gp_Pnt& P3, const gp_Pnt& P4) -{ - gp_Vec aVec1( P2.XYZ() - P1.XYZ() ); - gp_Vec aVec2( P3.XYZ() - P1.XYZ() ); - gp_Vec aNorm = aVec1 ^ aVec2; - aNorm /= aNorm.Magnitude(); - gp_Vec aVec3( P4.XYZ() - P1.XYZ() ); - double aDist = aVec1 * aVec2; - return fabs( aDist ); -} + inline double getVolume2(double theLen[6]){ + double a2 = theLen[0]*theLen[0]; + double b2 = theLen[1]*theLen[1]; + double c2 = theLen[2]*theLen[2]; + double d2 = theLen[3]*theLen[3]; + double e2 = theLen[4]*theLen[4]; + double f2 = theLen[5]*theLen[5]; + + double P = a2*e2*(b2+c2+d2+f2-a2-e2); + double Q = b2*f2*(a2+c2+d2+e2-b2-f2); + double R = c2*d2*(a2+b2+e2+f2-c2-d2); + double S = a2*b2*d2+b2*c2*e2+a2*c2*f2+d2*e2*f2; + + return sqrt(P+Q+R-S)/12.0; + } + + inline double getVolume(const TSequenceOfXYZ& P){ + gp_Vec aVec1( P( 2 ) - P( 1 ) ); + gp_Vec aVec2( P( 3 ) - P( 1 ) ); + gp_Vec aVec3( P( 4 ) - P( 1 ) ); + gp_Vec anAreaVec( aVec1 ^ aVec2 ); + return abs(aVec3 * anAreaVec) / 6.0; + } + + inline double getMaxHeight(double theLen[6]) + { + double aHeight = max(theLen[0],theLen[1]); + aHeight = max(aHeight,theLen[2]); + aHeight = max(aHeight,theLen[3]); + aHeight = max(aHeight,theLen[4]); + aHeight = max(aHeight,theLen[5]); + return aHeight; + } -static inline double getMaxHeight( const TColgp_SequenceOfXYZ& P ) -{ - double aHeight = getHeight(P(1),P(2),P(3),P(4)); - aHeight = max(aHeight,getHeight(P(1),P(2),P(4),P(3))); - aHeight = max(aHeight,getHeight(P(1),P(3),P(4),P(2))); - aHeight = max(aHeight,getHeight(P(2),P(3),P(4),P(1))); - return aHeight; } -double AspectRatio3D::GetValue( const TColgp_SequenceOfXYZ& P ) +double AspectRatio3D::GetValue( const TSequenceOfXYZ& P ) { double aQuality = 0.0; - int nbNodes = P.Length(); + int nbNodes = P.size(); switch(nbNodes){ case 4:{ double aLen[6] = { - getDistance(P(1),P(2)), // a - getDistance(P(2),P(3)), // b - getDistance(P(3),P(1)), // c - getDistance(P(2),P(4)), // d - getDistance(P(3),P(4)), // e - getDistance(P(1),P(4)) // f + getDistance(P( 1 ),P( 2 )), // a + getDistance(P( 2 ),P( 3 )), // b + getDistance(P( 3 ),P( 1 )), // c + getDistance(P( 2 ),P( 4 )), // d + getDistance(P( 3 ),P( 4 )), // e + getDistance(P( 1 ),P( 4 )) // f }; double aTria[4][3] = { {aLen[0],aLen[1],aLen[2]}, // abc @@ -372,15 +388,205 @@ double AspectRatio3D::GetValue( const TColgp_SequenceOfXYZ& P ) {aLen[1],aLen[3],aLen[4]}, // bde {aLen[2],aLen[4],aLen[5]} // cef }; - double aHalfPerim = getHalfPerimeter(aTria[0]); - double anArea = getArea(aHalfPerim,aTria[0]); - aHalfPerim = getHalfPerimeter(aTria[1]); - anArea += getArea(aHalfPerim,aTria[1]); - aHalfPerim = getHalfPerimeter(aTria[2]); - anArea += getArea(aHalfPerim,aTria[2]); - double aVolume = getVolume(aLen); - double aHeight = getMaxHeight(P); - aQuality = 1.0/3.0*aHeight*anArea/aVolume; + double aSumArea = 0.0; + double aHalfPerimeter = getHalfPerimeter(aTria[0]); + double anArea = getArea(aHalfPerimeter,aTria[0]); + aSumArea += anArea; + aHalfPerimeter = getHalfPerimeter(aTria[1]); + anArea = getArea(aHalfPerimeter,aTria[1]); + aSumArea += anArea; + aHalfPerimeter = getHalfPerimeter(aTria[2]); + anArea = getArea(aHalfPerimeter,aTria[2]); + aSumArea += anArea; + aHalfPerimeter = getHalfPerimeter(aTria[3]); + anArea = getArea(aHalfPerimeter,aTria[3]); + aSumArea += anArea; + double aVolume = getVolume(P); + //double aVolume = getVolume(aLen); + double aHeight = getMaxHeight(aLen); + static double aCoeff = sqrt(6.0)/36.0; + aQuality = aCoeff*aHeight*aSumArea/aVolume; + break; + } + case 5:{ + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 3 ),P( 5 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 3 ),P( 4 ),P( 5 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 5 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 4 ),P( 5 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + break; + } + case 6:{ + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 6 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 3 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 6 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 6 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 2 ),P( 5 ),P( 4 ),P( 3 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + break; + } + case 8:{ + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 3 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 4 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 7 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 5 ),P( 8 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 3 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 4 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 7 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 6 ),P( 8 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 3 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 4 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 7 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 2 ),P( 6 ),P( 5 ),P( 8 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 1 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 2 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 5 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 8 ),P( 6 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 1 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 2 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 5 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 7 ),P( 6 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 1 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 5 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 6 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 4 ),P( 8 ),P( 7 ),P( 2 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 4 ),P( 5 ),P( 8 ),P( 2 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 4 ),P( 5 ),P( 3 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 3 ),P( 6 ),P( 7 ),P( 1 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 2 ),P( 3 ),P( 6 ),P( 4 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 5 ),P( 6 ),P( 8 ),P( 3 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 7 ),P( 8 ),P( 6 ),P( 1 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 1 ),P( 2 ),P( 4 ),P( 7 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } + { + gp_XYZ aXYZ[4] = {P( 3 ),P( 4 ),P( 2 ),P( 5 )}; + aQuality = max(GetValue(TSequenceOfXYZ(&aXYZ[0],&aXYZ[4])),aQuality); + } break; } } @@ -405,9 +611,9 @@ SMDSAbs_ElementType AspectRatio3D::GetType() const Class : Warping Description : Functor for calculating warping */ -double Warping::GetValue( const TColgp_SequenceOfXYZ& P ) +double Warping::GetValue( const TSequenceOfXYZ& P ) { - if ( P.Length() != 4 ) + if ( P.size() != 4 ) return 0; gp_XYZ G = ( P( 1 ) + P( 2 ) + P( 3 ) + P( 4 ) ) / 4; @@ -462,9 +668,9 @@ SMDSAbs_ElementType Warping::GetType() const Class : Taper Description : Functor for calculating taper */ -double Taper::GetValue( const TColgp_SequenceOfXYZ& P ) +double Taper::GetValue( const TSequenceOfXYZ& P ) { - if ( P.Length() != 4 ) + if ( P.size() != 4 ) return 0; // Compute taper @@ -514,14 +720,14 @@ static inline double skewAngle( const gp_XYZ& p1, const gp_XYZ& p2, const gp_XYZ return v1.Magnitude() < gp::Resolution() || v2.Magnitude() < gp::Resolution() ? 0 : v1.Angle( v2 ); } -double Skew::GetValue( const TColgp_SequenceOfXYZ& P ) +double Skew::GetValue( const TSequenceOfXYZ& P ) { - if ( P.Length() != 3 && P.Length() != 4 ) + if ( P.size() != 3 && P.size() != 4 ) return 0; // Compute skew static double PI2 = PI / 2; - if ( P.Length() == 3 ) + if ( P.size() == 3 ) { double A0 = fabs( PI2 - skewAngle( P( 3 ), P( 1 ), P( 2 ) ) ); double A1 = fabs( PI2 - skewAngle( P( 1 ), P( 2 ), P( 3 ) ) ); @@ -562,11 +768,11 @@ SMDSAbs_ElementType Skew::GetType() const Class : Area Description : Functor for calculating area */ -double Area::GetValue( const TColgp_SequenceOfXYZ& P ) +double Area::GetValue( const TSequenceOfXYZ& P ) { - if ( P.Length() == 3 ) + if ( P.size() == 3 ) return getArea( P( 1 ), P( 2 ), P( 3 ) ); - else if ( P.Length() == 4 ) + else if ( P.size() == 4 ) return getArea( P( 1 ), P( 2 ), P( 3 ) ) + getArea( P( 1 ), P( 3 ), P( 4 ) ); else return 0; @@ -587,9 +793,9 @@ SMDSAbs_ElementType Area::GetType() const Class : Length Description : Functor for calculating length off edge */ -double Length::GetValue( const TColgp_SequenceOfXYZ& P ) +double Length::GetValue( const TSequenceOfXYZ& P ) { - return ( P.Length() == 2 ? getDistance( P( 1 ), P( 2 ) ) : 0 ); + return ( P.size() == 2 ? getDistance( P( 1 ), P( 2 ) ) : 0 ); } double Length::GetBadRate( double Value, int /*nbNodes*/ ) const @@ -602,12 +808,198 @@ SMDSAbs_ElementType Length::GetType() const return SMDSAbs_Edge; } +/* + Class : Length2D + Description : Functor for calculating length of edge +*/ + +double Length2D::GetValue( long theElementId) +{ + TSequenceOfXYZ P; + + if (GetPoints(theElementId,P)){ + + double aVal;// = GetValue( P ); + const SMDS_MeshElement* aElem = myMesh->FindElement( theElementId ); + SMDSAbs_ElementType aType = aElem->GetType(); + + int len = P.size(); + + switch (aType){ + case SMDSAbs_All: + case SMDSAbs_Node: + case SMDSAbs_Edge: + if (len == 2){ + aVal = getDistance( P( 1 ), P( 2 ) ); + break; + } + case SMDSAbs_Face: + if (len == 3){ // triangles + double L1 = getDistance(P( 1 ),P( 2 )); + double L2 = getDistance(P( 2 ),P( 3 )); + double L3 = getDistance(P( 3 ),P( 1 )); + aVal = Max(L1,Max(L2,L3)); + break; + } + else if (len == 4){ // quadrangles + double L1 = getDistance(P( 1 ),P( 2 )); + double L2 = getDistance(P( 2 ),P( 3 )); + double L3 = getDistance(P( 3 ),P( 4 )); + double L4 = getDistance(P( 4 ),P( 1 )); + aVal = Max(Max(L1,L2),Max(L3,L4)); + break; + } + case SMDSAbs_Volume: + if (len == 4){ // tetraidrs + double L1 = getDistance(P( 1 ),P( 2 )); + double L2 = getDistance(P( 2 ),P( 3 )); + double L3 = getDistance(P( 3 ),P( 1 )); + double L4 = getDistance(P( 1 ),P( 4 )); + double L5 = getDistance(P( 2 ),P( 4 )); + double L6 = getDistance(P( 3 ),P( 4 )); + aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6)); + break; + } + else if (len == 5){ // piramids + double L1 = getDistance(P( 1 ),P( 2 )); + double L2 = getDistance(P( 2 ),P( 3 )); + double L3 = getDistance(P( 3 ),P( 1 )); + double L4 = getDistance(P( 4 ),P( 1 )); + double L5 = getDistance(P( 1 ),P( 5 )); + double L6 = getDistance(P( 2 ),P( 5 )); + double L7 = getDistance(P( 3 ),P( 5 )); + double L8 = getDistance(P( 4 ),P( 5 )); + + aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6)); + aVal = Max(aVal,Max(L7,L8)); + break; + } + else if (len == 6){ // pentaidres + double L1 = getDistance(P( 1 ),P( 2 )); + double L2 = getDistance(P( 2 ),P( 3 )); + double L3 = getDistance(P( 3 ),P( 1 )); + double L4 = getDistance(P( 4 ),P( 5 )); + double L5 = getDistance(P( 5 ),P( 6 )); + double L6 = getDistance(P( 6 ),P( 4 )); + double L7 = getDistance(P( 1 ),P( 4 )); + double L8 = getDistance(P( 2 ),P( 5 )); + double L9 = getDistance(P( 3 ),P( 6 )); + + aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6)); + aVal = Max(aVal,Max(Max(L7,L8),L9)); + break; + } + else if (len == 8){ // hexaider + double L1 = getDistance(P( 1 ),P( 2 )); + double L2 = getDistance(P( 2 ),P( 3 )); + double L3 = getDistance(P( 3 ),P( 4 )); + double L4 = getDistance(P( 4 ),P( 1 )); + double L5 = getDistance(P( 5 ),P( 6 )); + double L6 = getDistance(P( 6 ),P( 7 )); + double L7 = getDistance(P( 7 ),P( 8 )); + double L8 = getDistance(P( 8 ),P( 5 )); + double L9 = getDistance(P( 1 ),P( 5 )); + double L10= getDistance(P( 2 ),P( 6 )); + double L11= getDistance(P( 3 ),P( 7 )); + double L12= getDistance(P( 4 ),P( 8 )); + + aVal = Max(Max(Max(L1,L2),Max(L3,L4)),Max(L5,L6)); + aVal = Max(aVal,Max(Max(L7,L8),Max(L9,L10))); + aVal = Max(aVal,Max(L11,L12)); + break; + + } + + default: aVal=-1; + } + + if (aVal <0){ + return 0.; + } + + if ( myPrecision >= 0 ) + { + double prec = pow( 10., (double)( myPrecision ) ); + aVal = floor( aVal * prec + 0.5 ) / prec; + } + + return aVal; + + } + return 0.; +} + +double Length2D::GetBadRate( double Value, int /*nbNodes*/ ) const +{ + return Value; +} + +SMDSAbs_ElementType Length2D::GetType() const +{ + return SMDSAbs_Face; +} + +Length2D::Value::Value(double theLength,long thePntId1, long thePntId2): + myLength(theLength) +{ + myPntId[0] = thePntId1; myPntId[1] = thePntId2; + if(thePntId1 > thePntId2){ + myPntId[1] = thePntId1; myPntId[0] = thePntId2; + } +} + +bool Length2D::Value::operator<(const Length2D::Value& x) const{ + if(myPntId[0] < x.myPntId[0]) return true; + if(myPntId[0] == x.myPntId[0]) + if(myPntId[1] < x.myPntId[1]) return true; + return false; +} + +void Length2D::GetValues(TValues& theValues){ + TValues aValues; + SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); + for(; anIter->more(); ){ + const SMDS_MeshFace* anElem = anIter->next(); + SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator(); + long aNodeId[2]; + gp_Pnt P[3]; + + double aLength; + const SMDS_MeshElement* aNode; + if(aNodesIter->more()){ + aNode = aNodesIter->next(); + const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode; + P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z()); + aNodeId[0] = aNodeId[1] = aNode->GetID(); + aLength = 0; + } + for(; aNodesIter->more(); ){ + aNode = aNodesIter->next(); + const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode; + long anId = aNode->GetID(); + + P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z()); + + aLength = P[1].Distance(P[2]); + + Value aValue(aLength,aNodeId[1],anId); + aNodeId[1] = anId; + P[1] = P[2]; + theValues.insert(aValue); + } + + aLength = P[0].Distance(P[1]); + + Value aValue(aLength,aNodeId[0],aNodeId[1]); + theValues.insert(aValue); + } +} /* Class : MultiConnection Description : Functor for calculating number of faces conneted to the edge */ -double MultiConnection::GetValue( const TColgp_SequenceOfXYZ& P ) +double MultiConnection::GetValue( const TSequenceOfXYZ& P ) { return 0; } @@ -626,6 +1018,148 @@ SMDSAbs_ElementType MultiConnection::GetType() const return SMDSAbs_Edge; } +/* + Class : MultiConnection2D + Description : Functor for calculating number of faces conneted to the edge +*/ +double MultiConnection2D::GetValue( const TSequenceOfXYZ& P ) +{ + return 0; +} + +double MultiConnection2D::GetValue( long theElementId ) +{ + TSequenceOfXYZ P; + int aResult = 0; + + if (GetPoints(theElementId,P)){ + double aVal; + const SMDS_MeshElement* anFaceElem = myMesh->FindElement( theElementId ); + SMDSAbs_ElementType aType = anFaceElem->GetType(); + + int len = P.size(); + + TColStd_MapOfInteger aMap; + int aResult = 0; + + switch (aType){ + case SMDSAbs_All: + case SMDSAbs_Node: + case SMDSAbs_Edge: + case SMDSAbs_Face: + if (len == 3){ // triangles + int Nb[3] = {0,0,0}; + + int i=0; + SMDS_ElemIteratorPtr anIter = anFaceElem->nodesIterator(); + if ( anIter != 0 ) { + while( anIter->more() ) { + const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next(); + if ( aNode == 0 ){ + break; + } + SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator(); + while( anElemIter->more() ) { + const SMDS_MeshElement* anElem = anElemIter->next(); + if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) { + int anId = anElem->GetID(); + + if ( anIter->more() ) // i.e. first node + aMap.Add( anId ); + else if ( aMap.Contains( anId ) ){ + Nb[i]++; + } + } + else if ( anElem != 0 && anElem->GetType() == SMDSAbs_Edge ) i++; + } + } + } + + aResult = Max(Max(Nb[0],Nb[1]),Nb[2]); + } + break; + case SMDSAbs_Volume: + default: aResult=0; + } + + } + return aResult;//getNbMultiConnection( myMesh, theId ); +} + +double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const +{ + return Value; +} + +SMDSAbs_ElementType MultiConnection2D::GetType() const +{ + return SMDSAbs_Face; +} + +MultiConnection2D::Value::Value(long thePntId1, long thePntId2) +{ + myPntId[0] = thePntId1; myPntId[1] = thePntId2; + if(thePntId1 > thePntId2){ + myPntId[1] = thePntId1; myPntId[0] = thePntId2; + } +} + +bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{ + if(myPntId[0] < x.myPntId[0]) return true; + if(myPntId[0] == x.myPntId[0]) + if(myPntId[1] < x.myPntId[1]) return true; + return false; +} + +void MultiConnection2D::GetValues(MValues& theValues){ + SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); + for(; anIter->more(); ){ + const SMDS_MeshFace* anElem = anIter->next(); + long anElemId = anElem->GetID(); + SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator(); + long aNodeId[3]; + + //int aNbConnects=0; + const SMDS_MeshNode* aNode0; + const SMDS_MeshNode* aNode1; + const SMDS_MeshNode* aNode2; + if(aNodesIter->more()){ + aNode0 = (SMDS_MeshNode*) aNodesIter->next(); + aNode1 = aNode0; + const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1; + aNodeId[0] = aNodeId[1] = aNodes->GetID(); + } + for(; aNodesIter->more(); ){ + aNode2 = (SMDS_MeshNode*) aNodesIter->next(); + long anId = aNode2->GetID(); + aNodeId[2] = anId; + + Value aValue(aNodeId[1],aNodeId[2]); + MValues::iterator aItr = theValues.find(aValue); + if (aItr != theValues.end()){ + aItr->second += 1; + //aNbConnects = nb; + } else { + theValues[aValue] = 1; + //aNbConnects = 1; + } + //cout << "NodeIds: "< -#include -#include -#include - -class SMDS_Mesh; -class SMESHDS_Mesh; -class SMESHDS_SubMesh; -class gp_Pnt; -class gp_XYZ; -class TColgp_SequenceOfXYZ; -class TopoDS_Shape; -class SMDS_MeshElement; -class SMDS_MeshFace; -class SMDS_MeshNode; namespace SMESH{ namespace Controls{ - class Functor - { - public: - ~Functor(){} - virtual void SetMesh( SMDS_Mesh* theMesh ) = 0; - virtual SMDSAbs_ElementType GetType() const = 0; - }; + + class Functor; typedef boost::shared_ptr FunctorPtr; - class NumericalFunctor: public virtual Functor{ - public: - NumericalFunctor(); - virtual void SetMesh( SMDS_Mesh* theMesh ); - virtual double GetValue( long theElementId ); - virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints ) = 0; - virtual SMDSAbs_ElementType GetType() const = 0; - virtual double GetBadRate( double Value, int nbNodes ) const = 0; - long GetPrecision() const; - void SetPrecision( const long thePrecision ); - - bool GetPoints (const int theId, - TColgp_SequenceOfXYZ& theRes ) const; - static bool GetPoints (const SMDS_MeshElement* theElem, - TColgp_SequenceOfXYZ& theRes ); - protected: - SMDS_Mesh* myMesh; - long myPrecision; - }; + + class NumericalFunctor; typedef boost::shared_ptr NumericalFunctorPtr; - /* - Class : SMESH_MinimumAngle - Description : Functor for calculation of minimum angle - */ - class MinimumAngle: public virtual NumericalFunctor{ - public: - virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints ); - virtual double GetBadRate( double Value, int nbNodes ) const; - virtual SMDSAbs_ElementType GetType() const; - }; - - - /* - Class : AspectRatio - Description : Functor for calculating aspect ratio - */ - class AspectRatio: public virtual NumericalFunctor{ - public: - virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints ); - virtual double GetBadRate( double Value, int nbNodes ) const; - virtual SMDSAbs_ElementType GetType() const; - }; - - - /* - Class : AspectRatio3D - Description : Functor for calculating aspect ratio of 3D elems. - */ - class AspectRatio3D: public virtual NumericalFunctor{ - public: - virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints ); - virtual double GetBadRate( double Value, int nbNodes ) const; - virtual SMDSAbs_ElementType GetType() const; - }; - - - /* - Class : Warping - Description : Functor for calculating warping - */ - class Warping: public virtual NumericalFunctor{ - public: - virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints ); - virtual double GetBadRate( double Value, int nbNodes ) const; - virtual SMDSAbs_ElementType GetType() const; - - private: - double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const; - }; - - - /* - Class : Taper - Description : Functor for calculating taper - */ - class Taper: public virtual NumericalFunctor{ - public: - virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints ); - virtual double GetBadRate( double Value, int nbNodes ) const; - virtual SMDSAbs_ElementType GetType() const; - }; - - - /* - Class : Skew - Description : Functor for calculating skew in degrees - */ - class Skew: public virtual NumericalFunctor{ - public: - virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints ); - virtual double GetBadRate( double Value, int nbNodes ) const; - virtual SMDSAbs_ElementType GetType() const; - }; - - - /* - Class : Area - Description : Functor for calculating area - */ - class Area: public virtual NumericalFunctor{ - public: - virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints ); - virtual double GetBadRate( double Value, int nbNodes ) const; - virtual SMDSAbs_ElementType GetType() const; - }; - - - /* - Class : Length - Description : Functor for calculating length of edge - */ - class Length: public virtual NumericalFunctor{ - public: - virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints ); - virtual double GetBadRate( double Value, int nbNodes ) const; - virtual SMDSAbs_ElementType GetType() const; - }; - - - /* - Class : MultiConnection - Description : Functor for calculating number of faces conneted to the edge - */ - class MultiConnection: public virtual NumericalFunctor{ - public: - virtual double GetValue( long theElementId ); - virtual double GetValue( const TColgp_SequenceOfXYZ& thePoints ); - virtual double GetBadRate( double Value, int nbNodes ) const; - virtual SMDSAbs_ElementType GetType() const; - }; - - - /* - PREDICATES - */ - /* - Class : Predicate - Description : Base class for all predicates - */ - class Predicate: public virtual Functor{ - public: - virtual bool IsSatisfy( long theElementId ) = 0; - virtual SMDSAbs_ElementType GetType() const = 0; - }; + class Predicate; typedef boost::shared_ptr PredicatePtr; - - - - /* - Class : FreeBorders - Description : Predicate for free borders - */ - class FreeBorders: public virtual Predicate{ - public: - FreeBorders(); - virtual void SetMesh( SMDS_Mesh* theMesh ); - virtual bool IsSatisfy( long theElementId ); - virtual SMDSAbs_ElementType GetType() const; - - protected: - SMDS_Mesh* myMesh; - }; - - - /* - Class : FreeEdges - Description : Predicate for free Edges - */ - class FreeEdges: public virtual Predicate{ - public: - FreeEdges(); - virtual void SetMesh( SMDS_Mesh* theMesh ); - virtual bool IsSatisfy( long theElementId ); - virtual SMDSAbs_ElementType GetType() const; - static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId ); - typedef long TElemId; - struct Border{ - TElemId myElemId; - TElemId myPntId[2]; - Border(long theElemId, long thePntId1, long thePntId2); - bool operator<(const Border& x) const; - }; - typedef std::set TBorders; - void GetBoreders(TBorders& theBorders); - - protected: - SMDS_Mesh* myMesh; - }; - typedef boost::shared_ptr FreeEdgesPtr; - - /* - Class : RangeOfIds - Description : Predicate for Range of Ids. - Range may be specified with two ways. - 1. Using AddToRange method - 2. With SetRangeStr method. Parameter of this method is a string - like as "1,2,3,50-60,63,67,70-" - */ - class RangeOfIds: public virtual Predicate - { - public: - RangeOfIds(); - virtual void SetMesh( SMDS_Mesh* theMesh ); - virtual bool IsSatisfy( long theNodeId ); - virtual SMDSAbs_ElementType GetType() const; - virtual void SetType( SMDSAbs_ElementType theType ); - - bool AddToRange( long theEntityId ); - void GetRangeStr( TCollection_AsciiString& ); - bool SetRangeStr( const TCollection_AsciiString& ); - - protected: - SMDS_Mesh* myMesh; - - TColStd_SequenceOfInteger myMin; - TColStd_SequenceOfInteger myMax; - TColStd_MapOfInteger myIds; - - SMDSAbs_ElementType myType; - }; - - typedef boost::shared_ptr RangeOfIdsPtr; - - - /* - Class : Comparator - Description : Base class for comparators - */ - class Comparator: public virtual Predicate{ - public: - Comparator(); - virtual ~Comparator(); - virtual void SetMesh( SMDS_Mesh* theMesh ); - virtual void SetMargin(double theValue); - virtual void SetNumFunctor(NumericalFunctorPtr theFunct); - virtual bool IsSatisfy( long theElementId ) = 0; - virtual SMDSAbs_ElementType GetType() const; - double GetMargin(); - - protected: - double myMargin; - NumericalFunctorPtr myFunctor; - }; - typedef boost::shared_ptr ComparatorPtr; - - - /* - Class : LessThan - Description : Comparator "<" - */ - class LessThan: public virtual Comparator{ - public: - virtual bool IsSatisfy( long theElementId ); - }; - - - /* - Class : MoreThan - Description : Comparator ">" - */ - class MoreThan: public virtual Comparator{ - public: - virtual bool IsSatisfy( long theElementId ); - }; - - - /* - Class : EqualTo - Description : Comparator "=" - */ - class EqualTo: public virtual Comparator{ - public: - EqualTo(); - virtual bool IsSatisfy( long theElementId ); - virtual void SetTolerance( double theTol ); - virtual double GetTolerance(); - - private: - double myToler; - }; - typedef boost::shared_ptr EqualToPtr; - - - /* - Class : LogicalNOT - Description : Logical NOT predicate - */ - class LogicalNOT: public virtual Predicate{ - public: - LogicalNOT(); - virtual ~LogicalNOT(); - virtual bool IsSatisfy( long theElementId ); - virtual void SetMesh( SMDS_Mesh* theMesh ); - virtual void SetPredicate(PredicatePtr thePred); - virtual SMDSAbs_ElementType GetType() const; - - private: - PredicatePtr myPredicate; - }; - typedef boost::shared_ptr LogicalNOTPtr; - - - /* - Class : LogicalBinary - Description : Base class for binary logical predicate - */ - class LogicalBinary: public virtual Predicate{ - public: - LogicalBinary(); - virtual ~LogicalBinary(); - virtual void SetMesh( SMDS_Mesh* theMesh ); - virtual void SetPredicate1(PredicatePtr thePred); - virtual void SetPredicate2(PredicatePtr thePred); - virtual SMDSAbs_ElementType GetType() const; - - protected: - PredicatePtr myPredicate1; - PredicatePtr myPredicate2; - }; - typedef boost::shared_ptr LogicalBinaryPtr; - - - /* - Class : LogicalAND - Description : Logical AND - */ - class LogicalAND: public virtual LogicalBinary{ - public: - virtual bool IsSatisfy( long theElementId ); - }; - - - /* - Class : LogicalOR - Description : Logical OR - */ - class LogicalOR: public virtual LogicalBinary{ - public: - virtual bool IsSatisfy( long theElementId ); - }; - - - /* - Class : ManifoldPart - Description : Predicate for manifold part of mesh - */ - class ManifoldPart: public virtual Predicate{ - public: - - /* internal class for algorithm uses */ - class Link - { - public: - Link( SMDS_MeshNode* theNode1, - SMDS_MeshNode* theNode2 ); - ~Link(); - - bool IsEqual( const ManifoldPart::Link& theLink ) const; - bool operator<(const ManifoldPart::Link& x) const; - - SMDS_MeshNode* myNode1; - SMDS_MeshNode* myNode2; - }; - - bool IsEqual( const ManifoldPart::Link& theLink1, - const ManifoldPart::Link& theLink2 ); - - typedef std::set TMapOfLink; - typedef std::vector TVectorOfFacePtr; - typedef std::vector TVectorOfLink; - typedef std::map TDataMapFacePtrInt; - typedef std::map TDataMapOfLinkFacePtr; - - ManifoldPart(); - ~ManifoldPart(); - virtual void SetMesh( SMDS_Mesh* theMesh ); - // inoke when all parameters already set - virtual bool IsSatisfy( long theElementId ); - virtual SMDSAbs_ElementType GetType() const; - - void SetAngleTolerance( const double theAngToler ); - double GetAngleTolerance() const; - void SetIsOnlyManifold( const bool theIsOnly ); - void SetStartElem( const long theStartElemId ); - - private: - bool process(); - bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt, - SMDS_MeshFace* theStartFace, - TMapOfLink& theNonManifold, - TColStd_MapOfInteger& theResFaces ); - bool isInPlane( const SMDS_MeshFace* theFace1, - const SMDS_MeshFace* theFace2 ); - void expandBoundary( TMapOfLink& theMapOfBoundary, - TVectorOfLink& theSeqOfBoundary, - TDataMapOfLinkFacePtr& theDMapLinkFacePtr, - TMapOfLink& theNonManifold, - SMDS_MeshFace* theNextFace ) const; - - void getFacesByLink( const Link& theLink, - TVectorOfFacePtr& theFaces ) const; - - private: - SMDS_Mesh* myMesh; - TColStd_MapOfInteger myMapIds; - TColStd_MapOfInteger myMapBadGeomIds; - TVectorOfFacePtr myAllFacePtr; - TDataMapFacePtrInt myAllFacePtrIntDMap; - double myAngToler; - bool myIsOnlyManifold; - long myStartElemId; - - }; - typedef boost::shared_ptr ManifoldPartPtr; - - - /* - Class : ElementsOnSurface - Description : Predicate elements that lying on indicated surface - (plane or cylinder) - */ - class ElementsOnSurface : public virtual Predicate { - public: - ElementsOnSurface(); - ~ElementsOnSurface(); - virtual void SetMesh( SMDS_Mesh* theMesh ); - virtual bool IsSatisfy( long theElementId ); - virtual SMDSAbs_ElementType GetType() const; - - void SetTolerance( const double theToler ); - double GetTolerance() const; - void SetSurface( const TopoDS_Shape& theShape, - const SMDSAbs_ElementType theType ); - - private: - void process(); - void process( const SMDS_MeshElement* theElem ); - bool isOnSurface( const SMDS_MeshNode* theNode ) const; - - private: - SMDS_Mesh* myMesh; - TColStd_MapOfInteger myIds; - SMDSAbs_ElementType myType; - Handle(Geom_Surface) mySurf; - double myToler; - }; - - typedef boost::shared_ptr ElementsOnSurfacePtr; - - - /* - FILTER - */ - class Filter{ - public: - Filter(); - virtual ~Filter(); - virtual void SetPredicate(PredicatePtr thePred); - typedef std::vector TIdSequence; - virtual TIdSequence GetElementsId( SMDS_Mesh* theMesh ); - - protected: - PredicatePtr myPredicate; - }; - }; -}; + } +} #endif diff --git a/src/Controls/SMESH_ControlsDef.hxx b/src/Controls/SMESH_ControlsDef.hxx new file mode 100644 index 000000000..50fb06558 --- /dev/null +++ b/src/Controls/SMESH_ControlsDef.hxx @@ -0,0 +1,612 @@ +// 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 + +#ifndef _SMESH_CONTROLSDEF_HXX_ +#define _SMESH_CONTROLSDEF_HXX_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SMDSAbs_ElementType.hxx" +#include "SMDS_MeshNode.hxx" + +#include "SMESH_Controls.hxx" + +class SMDS_MeshElement; +class SMDS_MeshFace; +class SMDS_MeshNode; +class SMDS_Mesh; + +class SMESHDS_Mesh; +class SMESHDS_SubMesh; + +class gp_Pnt; +class TopoDS_Shape; + + +namespace SMESH{ + namespace Controls{ + + class TSequenceOfXYZ: public std::vector + { + public: + typedef std::vector TSuperClass; + TSequenceOfXYZ() + {} + + TSequenceOfXYZ(size_type n): + TSuperClass(n) + {} + + TSequenceOfXYZ(size_type n, const value_type& t): + TSuperClass(n,t) + {} + + TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ): + TSuperClass(theSequenceOfXYZ) + {} + + template + TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): + TSuperClass(theBegin,theEnd) + {} + + TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){ + TSuperClass::operator=(theSequenceOfXYZ); + return *this; + } + + reference operator()(size_type n){ + return TSuperClass::operator[](n-1); + } + + const_reference operator()(size_type n) const{ + return TSuperClass::operator[](n-1); + } + + private: + reference operator[](size_type n); + + const_reference operator[](size_type n) const; + }; + + class Functor + { + public: + ~Functor(){} + virtual void SetMesh( SMDS_Mesh* theMesh ) = 0; + virtual SMDSAbs_ElementType GetType() const = 0; + }; + + class NumericalFunctor: public virtual Functor{ + public: + NumericalFunctor(); + virtual void SetMesh( SMDS_Mesh* theMesh ); + virtual double GetValue( long theElementId ); + virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;}; + virtual SMDSAbs_ElementType GetType() const = 0; + virtual double GetBadRate( double Value, int nbNodes ) const = 0; + long GetPrecision() const; + void SetPrecision( const long thePrecision ); + + bool GetPoints(const int theId, + TSequenceOfXYZ& theRes) const; + static bool GetPoints(const SMDS_MeshElement* theElem, + TSequenceOfXYZ& theRes); + protected: + SMDS_Mesh* myMesh; + long myPrecision; + }; + + + /* + Class : SMESH_MinimumAngle + Description : Functor for calculation of minimum angle + */ + class MinimumAngle: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + + /* + Class : AspectRatio + Description : Functor for calculating aspect ratio + */ + class AspectRatio: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + + /* + Class : AspectRatio3D + Description : Functor for calculating aspect ratio of 3D elems. + */ + class AspectRatio3D: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + + /* + Class : Warping + Description : Functor for calculating warping + */ + class Warping: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + + private: + double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const; + }; + + + /* + Class : Taper + Description : Functor for calculating taper + */ + class Taper: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + + /* + Class : Skew + Description : Functor for calculating skew in degrees + */ + class Skew: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + + /* + Class : Area + Description : Functor for calculating area + */ + class Area: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + + /* + Class : Length + Description : Functor for calculating length of edge + */ + class Length: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + /* + Class : Length2D + Description : Functor for calculating length of edge + */ + class Length2D: public virtual NumericalFunctor{ + public: + virtual double GetValue( long theElementId ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + struct Value{ + double myLength; + long myPntId[2]; + Value(double theLength, long thePntId1, long thePntId2); + bool operator<(const Value& x) const; + }; + typedef std::set TValues; + void GetValues(TValues& theValues); + + }; + typedef boost::shared_ptr Length2DPtr; + + /* + Class : MultiConnection + Description : Functor for calculating number of faces conneted to the edge + */ + class MultiConnection: public virtual NumericalFunctor{ + public: + virtual double GetValue( long theElementId ); + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + /* + Class : MultiConnection2D + Description : Functor for calculating number of faces conneted to the edge + */ + class MultiConnection2D: public virtual NumericalFunctor{ + public: + virtual double GetValue( long theElementId ); + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + struct Value{ + long myPntId[2]; + Value(long thePntId1, long thePntId2); + bool operator<(const Value& x) const; + }; + typedef std::map MValues; + + void GetValues(MValues& theValues); + }; + typedef boost::shared_ptr MultiConnection2DPtr; + /* + PREDICATES + */ + /* + Class : Predicate + Description : Base class for all predicates + */ + class Predicate: public virtual Functor{ + public: + virtual bool IsSatisfy( long theElementId ) = 0; + virtual SMDSAbs_ElementType GetType() const = 0; + }; + + + + /* + Class : FreeBorders + Description : Predicate for free borders + */ + class FreeBorders: public virtual Predicate{ + public: + FreeBorders(); + virtual void SetMesh( SMDS_Mesh* theMesh ); + virtual bool IsSatisfy( long theElementId ); + virtual SMDSAbs_ElementType GetType() const; + + protected: + SMDS_Mesh* myMesh; + }; + + + /* + Class : FreeEdges + Description : Predicate for free Edges + */ + class FreeEdges: public virtual Predicate{ + public: + FreeEdges(); + virtual void SetMesh( SMDS_Mesh* theMesh ); + virtual bool IsSatisfy( long theElementId ); + virtual SMDSAbs_ElementType GetType() const; + static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId ); + typedef long TElemId; + struct Border{ + TElemId myElemId; + TElemId myPntId[2]; + Border(long theElemId, long thePntId1, long thePntId2); + bool operator<(const Border& x) const; + }; + typedef std::set TBorders; + void GetBoreders(TBorders& theBorders); + + protected: + SMDS_Mesh* myMesh; + }; + typedef boost::shared_ptr FreeEdgesPtr; + + + /* + Class : RangeOfIds + Description : Predicate for Range of Ids. + Range may be specified with two ways. + 1. Using AddToRange method + 2. With SetRangeStr method. Parameter of this method is a string + like as "1,2,3,50-60,63,67,70-" + */ + class RangeOfIds: public virtual Predicate + { + public: + RangeOfIds(); + virtual void SetMesh( SMDS_Mesh* theMesh ); + virtual bool IsSatisfy( long theNodeId ); + virtual SMDSAbs_ElementType GetType() const; + virtual void SetType( SMDSAbs_ElementType theType ); + + bool AddToRange( long theEntityId ); + void GetRangeStr( TCollection_AsciiString& ); + bool SetRangeStr( const TCollection_AsciiString& ); + + protected: + SMDS_Mesh* myMesh; + + TColStd_SequenceOfInteger myMin; + TColStd_SequenceOfInteger myMax; + TColStd_MapOfInteger myIds; + + SMDSAbs_ElementType myType; + }; + + typedef boost::shared_ptr RangeOfIdsPtr; + + + /* + Class : Comparator + Description : Base class for comparators + */ + class Comparator: public virtual Predicate{ + public: + Comparator(); + virtual ~Comparator(); + virtual void SetMesh( SMDS_Mesh* theMesh ); + virtual void SetMargin(double theValue); + virtual void SetNumFunctor(NumericalFunctorPtr theFunct); + virtual bool IsSatisfy( long theElementId ) = 0; + virtual SMDSAbs_ElementType GetType() const; + double GetMargin(); + + protected: + double myMargin; + NumericalFunctorPtr myFunctor; + }; + typedef boost::shared_ptr ComparatorPtr; + + + /* + Class : LessThan + Description : Comparator "<" + */ + class LessThan: public virtual Comparator{ + public: + virtual bool IsSatisfy( long theElementId ); + }; + + + /* + Class : MoreThan + Description : Comparator ">" + */ + class MoreThan: public virtual Comparator{ + public: + virtual bool IsSatisfy( long theElementId ); + }; + + + /* + Class : EqualTo + Description : Comparator "=" + */ + class EqualTo: public virtual Comparator{ + public: + EqualTo(); + virtual bool IsSatisfy( long theElementId ); + virtual void SetTolerance( double theTol ); + virtual double GetTolerance(); + + private: + double myToler; + }; + typedef boost::shared_ptr EqualToPtr; + + + /* + Class : LogicalNOT + Description : Logical NOT predicate + */ + class LogicalNOT: public virtual Predicate{ + public: + LogicalNOT(); + virtual ~LogicalNOT(); + virtual bool IsSatisfy( long theElementId ); + virtual void SetMesh( SMDS_Mesh* theMesh ); + virtual void SetPredicate(PredicatePtr thePred); + virtual SMDSAbs_ElementType GetType() const; + + private: + PredicatePtr myPredicate; + }; + typedef boost::shared_ptr LogicalNOTPtr; + + + /* + Class : LogicalBinary + Description : Base class for binary logical predicate + */ + class LogicalBinary: public virtual Predicate{ + public: + LogicalBinary(); + virtual ~LogicalBinary(); + virtual void SetMesh( SMDS_Mesh* theMesh ); + virtual void SetPredicate1(PredicatePtr thePred); + virtual void SetPredicate2(PredicatePtr thePred); + virtual SMDSAbs_ElementType GetType() const; + + protected: + PredicatePtr myPredicate1; + PredicatePtr myPredicate2; + }; + typedef boost::shared_ptr LogicalBinaryPtr; + + + /* + Class : LogicalAND + Description : Logical AND + */ + class LogicalAND: public virtual LogicalBinary{ + public: + virtual bool IsSatisfy( long theElementId ); + }; + + + /* + Class : LogicalOR + Description : Logical OR + */ + class LogicalOR: public virtual LogicalBinary{ + public: + virtual bool IsSatisfy( long theElementId ); + }; + + + /* + Class : ManifoldPart + Description : Predicate for manifold part of mesh + */ + class ManifoldPart: public virtual Predicate{ + public: + + /* internal class for algorithm uses */ + class Link + { + public: + Link( SMDS_MeshNode* theNode1, + SMDS_MeshNode* theNode2 ); + ~Link(); + + bool IsEqual( const ManifoldPart::Link& theLink ) const; + bool operator<(const ManifoldPart::Link& x) const; + + SMDS_MeshNode* myNode1; + SMDS_MeshNode* myNode2; + }; + + bool IsEqual( const ManifoldPart::Link& theLink1, + const ManifoldPart::Link& theLink2 ); + + typedef std::set TMapOfLink; + typedef std::vector TVectorOfFacePtr; + typedef std::vector TVectorOfLink; + typedef std::map TDataMapFacePtrInt; + typedef std::map TDataMapOfLinkFacePtr; + + ManifoldPart(); + ~ManifoldPart(); + virtual void SetMesh( SMDS_Mesh* theMesh ); + // inoke when all parameters already set + virtual bool IsSatisfy( long theElementId ); + virtual SMDSAbs_ElementType GetType() const; + + void SetAngleTolerance( const double theAngToler ); + double GetAngleTolerance() const; + void SetIsOnlyManifold( const bool theIsOnly ); + void SetStartElem( const long theStartElemId ); + + private: + bool process(); + bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt, + SMDS_MeshFace* theStartFace, + TMapOfLink& theNonManifold, + TColStd_MapOfInteger& theResFaces ); + bool isInPlane( const SMDS_MeshFace* theFace1, + const SMDS_MeshFace* theFace2 ); + void expandBoundary( TMapOfLink& theMapOfBoundary, + TVectorOfLink& theSeqOfBoundary, + TDataMapOfLinkFacePtr& theDMapLinkFacePtr, + TMapOfLink& theNonManifold, + SMDS_MeshFace* theNextFace ) const; + + void getFacesByLink( const Link& theLink, + TVectorOfFacePtr& theFaces ) const; + + private: + SMDS_Mesh* myMesh; + TColStd_MapOfInteger myMapIds; + TColStd_MapOfInteger myMapBadGeomIds; + TVectorOfFacePtr myAllFacePtr; + TDataMapFacePtrInt myAllFacePtrIntDMap; + double myAngToler; + bool myIsOnlyManifold; + long myStartElemId; + + }; + typedef boost::shared_ptr ManifoldPartPtr; + + + /* + Class : ElementsOnSurface + Description : Predicate elements that lying on indicated surface + (plane or cylinder) + */ + class ElementsOnSurface : public virtual Predicate { + public: + ElementsOnSurface(); + ~ElementsOnSurface(); + virtual void SetMesh( SMDS_Mesh* theMesh ); + virtual bool IsSatisfy( long theElementId ); + virtual SMDSAbs_ElementType GetType() const; + + void SetTolerance( const double theToler ); + double GetTolerance() const; + void SetSurface( const TopoDS_Shape& theShape, + const SMDSAbs_ElementType theType ); + + private: + void process(); + void process( const SMDS_MeshElement* theElem ); + bool isOnSurface( const SMDS_MeshNode* theNode ) const; + + private: + SMDS_Mesh* myMesh; + TColStd_MapOfInteger myIds; + SMDSAbs_ElementType myType; + Handle(Geom_Surface) mySurf; + double myToler; + }; + + typedef boost::shared_ptr ElementsOnSurfacePtr; + + + /* + FILTER + */ + class Filter{ + public: + Filter(); + virtual ~Filter(); + virtual void SetPredicate(PredicatePtr thePred); + typedef std::vector TIdSequence; + virtual TIdSequence GetElementsId( SMDS_Mesh* theMesh ); + + protected: + PredicatePtr myPredicate; + }; + }; +}; + + +#endif diff --git a/src/DriverDAT/Makefile.in b/src/DriverDAT/Makefile.in index a5d1daf61..23fcb3ae7 100644 --- a/src/DriverDAT/Makefile.in +++ b/src/DriverDAT/Makefile.in @@ -49,9 +49,9 @@ LIB_CLIENT_IDL = LIB_SERVER_IDL = # additionnal information to compil and link file -CPPFLAGS += -I${KERNEL_ROOT_DIR}/include/salome $(BOOST_CPPFLAGS) +CPPFLAGS += -I${KERNEL_ROOT_DIR}/include/salome $(OCC_INCLUDES) $(BOOST_CPPFLAGS) CXXFLAGS += -I${KERNEL_ROOT_DIR}/include/salome -LDFLAGS += -lMeshDriver +LDFLAGS += -lMeshDriver $(OCC_KERNEL_LIBS) LDFLAGSFORBIN += -lMeshDriver -lSMDS -L${KERNEL_ROOT_DIR}/lib/salome -lOpUtil -lSALOMELocalTrace diff --git a/src/DriverMED/DriverMED_Family.cxx b/src/DriverMED/DriverMED_Family.cxx index f40810c94..778c282a5 100644 --- a/src/DriverMED/DriverMED_Family.cxx +++ b/src/DriverMED/DriverMED_Family.cxx @@ -26,6 +26,8 @@ // $Header$ #include "DriverMED_Family.h" +#include "MED_Factory.hxx" + #include using namespace std; @@ -204,8 +206,9 @@ list DriverMED_Family::MakeFamilies * Create TFamilyInfo for this family */ //============================================================================= -MEDA::PFamilyInfo DriverMED_Family::GetFamilyInfo - (const MEDA::PMeshInfo& theMeshInfo) const +MED::PFamilyInfo +DriverMED_Family::GetFamilyInfo(const MED::PWrapper& theWrapper, + const MED::PMeshInfo& theMeshInfo) const { string aValue; ostringstream aStr; @@ -215,11 +218,13 @@ MEDA::PFamilyInfo DriverMED_Family::GetFamilyInfo MED::TIntVector anAttrIds (1, myId); // Id=0, MED::TIntVector anAttrVals (1, myId); // Value=0 - MEDA::PFamilyInfo anInfo = MEDA::TWrapper::CrFamilyInfo(theMeshInfo, - aValue, - myId, - myGroupNames, - anAttrDescs,anAttrIds,anAttrVals); + MED::PFamilyInfo anInfo = theWrapper->CrFamilyInfo(theMeshInfo, + aValue, + myId, + myGroupNames, + anAttrDescs, + anAttrIds, + anAttrVals); // cout << endl; // cout << "Groups: "; diff --git a/src/DriverMED/DriverMED_Family.h b/src/DriverMED/DriverMED_Family.h index b5fc51f2e..944b9bc82 100644 --- a/src/DriverMED/DriverMED_Family.h +++ b/src/DriverMED/DriverMED_Family.h @@ -31,7 +31,7 @@ #include "SMDS_Mesh.hxx" #include "SMESHDS_GroupBase.hxx" #include "SMESHDS_SubMesh.hxx" -#include "MEDA_Wrapper.hxx" +#include "MED_Common.hxx" #include #include @@ -63,7 +63,8 @@ class DriverMED_Family // from and other sub-meshes from . // Resulting families have no common elements. - MEDA::PFamilyInfo GetFamilyInfo (const MEDA::PMeshInfo& theMeshInfo) const; + MED::PFamilyInfo GetFamilyInfo (const MED::PWrapper& theWrapper, + const MED::PMeshInfo& theMeshInfo) const; // Create TFamilyInfo for this family const std::set& GetElements () const { return myElements; } diff --git a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx index 513454316..25e517cf4 100644 --- a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx @@ -33,20 +33,22 @@ #include "SMESHDS_Group.hxx" -#include "MEDA_Wrapper.hxx" +#include "MED_Factory.hxx" #include "MED_Utilities.hxx" #include #define _EDF_NODE_IDS_ +using namespace MED; + void DriverMED_R_SMESHDS_Mesh::SetMeshName(string theMeshName) { myMeshName = theMeshName; } static const SMDS_MeshNode* -FindNode(const SMDS_Mesh* theMesh, med_int theId){ +FindNode(const SMDS_Mesh* theMesh, TInt theId){ const SMDS_MeshNode* aNode = theMesh->FindNode(theId); if(aNode) return aNode; EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "< -med_float GetCoord(MEDA::PNodeInfo& thePNodeInfo, med_int theElemId){ +TFloat GetCoord(MED::PNodeInfo& thePNodeInfo, TInt theElemId){ return thePNodeInfo->GetNodeCoord(theElemId,TheCoordId); } template<> -med_float GetCoord(MEDA::PNodeInfo& thePNodeInfo, med_int theElemId){ +TFloat GetCoord(MED::PNodeInfo& thePNodeInfo, TInt theElemId){ return 0.0; } @@ -113,16 +115,16 @@ static TGetCoord aZGetCoord[3] = { class TCoordHelper{ - MEDA::PNodeInfo myPNodeInfo; + MED::PNodeInfo myPNodeInfo; TGetCoord* myGetCoord; public: - TCoordHelper(const MEDA::PNodeInfo& thePNodeInfo, + TCoordHelper(const MED::PNodeInfo& thePNodeInfo, TGetCoord* theGetCoord): myPNodeInfo(thePNodeInfo), myGetCoord(theGetCoord) {} virtual ~TCoordHelper(){} - med_float GetCoord(med_int theElemId, med_int theCoodId){ + TFloat GetCoord(TInt theElemId, TInt theCoodId){ return (*myGetCoord[theCoodId])(myPNodeInfo,theElemId); } }; @@ -133,18 +135,16 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() { Status aResult = DRS_FAIL; try{ - using namespace MEDA; - myFamilies.clear(); MESSAGE("Perform - myFile : "<GetNbMeshes()){ for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){ // Reading the MED mesh //--------------------- - PMeshInfo aMeshInfo = aMed.GetMeshInfo(iMesh); + PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1); string aMeshName; if (myMeshId != -1) { ostringstream aMeshNameStr; @@ -156,22 +156,22 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() MESSAGE("Perform - aMeshName : "<GetName()); if(aMeshName != aMeshInfo->GetName()) continue; aResult = DRS_OK; - med_int aMeshDim = aMeshInfo->GetDim(); + //TInt aMeshDim = aMeshInfo->GetDim(); // Reading MED families to the temporary structure //------------------------------------------------ - med_int aNbFams = aMed.GetNbFamilies(aMeshInfo); + TInt aNbFams = aMed->GetNbFamilies(aMeshInfo); MESSAGE("Read " << aNbFams << " families"); - for (med_int iFam = 0; iFam < aNbFams; iFam++) { - PFamilyInfo aFamilyInfo = aMed.GetFamilyInfo(aMeshInfo, iFam); - med_int aFamId = aFamilyInfo->GetId(); + for (TInt iFam = 0; iFam < aNbFams; iFam++) { + PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo, iFam+1); + TInt aFamId = aFamilyInfo->GetId(); MESSAGE("Family " << aFamId << " :"); DriverMED_FamilyPtr aFamily (new DriverMED_Family); - med_int aNbGrp = aFamilyInfo->GetNbGroup(); + TInt aNbGrp = aFamilyInfo->GetNbGroup(); MESSAGE("belong to " << aNbGrp << " groups"); - for (med_int iGr = 0; iGr < aNbGrp; iGr++) { + for (TInt iGr = 0; iGr < aNbGrp; iGr++) { string aGroupName = aFamilyInfo->GetGroupName(iGr); MESSAGE(aGroupName); aFamily->AddGroupName(aGroupName); @@ -181,13 +181,13 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() // Reading MED nodes to the corresponding SMDS structure //------------------------------------------------------ - PNodeInfo aNodeInfo = aMed.GetNodeInfo(aMeshInfo); + PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo); TCoordHelperPtr aCoordHelperPtr; { - med_int aMeshDimension = aMeshInfo->GetDim(); + TInt aMeshDimension = aMeshInfo->GetDim(); bool anIsDimPresent[3] = {false, false, false}; - for(med_int iDim = 0; iDim < aMeshDimension; iDim++){ + for(TInt iDim = 0; iDim < aMeshDimension; iDim++){ string aDimName = aNodeInfo->GetCoordName(iDim); if(aDimName == "x" || aDimName == "X") anIsDimPresent[eX] = true; @@ -219,12 +219,12 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() } } - med_booleen anIsNodeNum = aNodeInfo->IsElemNum(); - med_int aNbElems = aNodeInfo->GetNbElem(); + EBooleen anIsNodeNum = aNodeInfo->IsElemNum(); + TInt aNbElems = aNodeInfo->GetNbElem(); MESSAGE("Perform - aNodeInfo->GetNbElem() = "<X()<<", "<Y()<<", "<Z()<GetFamNum(iElem); + TInt aFamNum = aNodeInfo->GetFamNum(iElem); if (myFamilies.find(aFamNum) != myFamilies.end()) { myFamilies[aFamNum]->AddElement(aNode); @@ -248,58 +248,58 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() // Reading pre information about all MED cells //-------------------------------------------- bool takeNumbers = true; // initially we trust the numbers from file - MED::TEntityInfo aEntityInfo = aMed.GetEntityInfo(aMeshInfo); + MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo); MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin(); for(; anEntityIter != aEntityInfo.end(); anEntityIter++){ - const med_entite_maillage& anEntity = anEntityIter->first; - if(anEntity == MED_NOEUD) continue; + const EEntiteMaillage& anEntity = anEntityIter->first; + if(anEntity == eNOEUD) continue; // Reading MED cells to the corresponding SMDS structure //------------------------------------------------------ const MED::TGeom& aTGeom = anEntityIter->second; MED::TGeom::const_iterator anTGeomIter = aTGeom.begin(); for(; anTGeomIter != aTGeom.end(); anTGeomIter++){ - const med_geometrie_element& aGeom = anTGeomIter->first; - if(aGeom == MED_POINT1) continue; - PCellInfo aCellInfo = aMed.GetCellInfo(aMeshInfo,anEntity,aGeom); - med_booleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : MED_FAUX; - med_int aNbElems = aCellInfo->GetNbElem(); + const EGeometrieElement& aGeom = anTGeomIter->first; + if(aGeom == ePOINT1) continue; + PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom); + EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX; + TInt aNbElems = aCellInfo->GetNbElem(); MESSAGE("Perform - anEntity = "<GetNbMeshes()) { for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) { // Reading the MED mesh //--------------------- - PMeshInfo aMeshInfo = aMed.GetMeshInfo(iMesh); + PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1); aMeshNames.push_back(aMeshInfo->GetName()); } } diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx index 6bdfc09be..cf7d9a819 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx @@ -35,13 +35,15 @@ #include "SMDS_MeshNode.hxx" #include "utilities.h" -#include "MEDA_Wrapper.hxx" +#include "MED_Factory.hxx" #include "MED_Utilities.hxx" #define _EDF_NODE_IDS_ //#define _ELEMENTS_BY_DIM_ using namespace std; +using namespace MED; + DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh(): myAllSubMeshes (false), @@ -51,6 +53,17 @@ DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh(): myDoGroupOfVolumes (false) {} +void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, MED::EVersion theId) +{ + myMed = CrWrapper(theFileName,theId); + Driver_SMESHDS_Mesh::SetFile(theFileName); +} + +void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName) +{ + return SetFile(theFileName,MED::eV2_1); +} + void DriverMED_W_SMESHDS_Mesh::SetMeshName(const std::string& theMeshName) { myMeshName = theMeshName; @@ -91,95 +104,98 @@ void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes() myDoGroupOfVolumes = true; } -typedef double (SMDS_MeshNode::* TGetCoord)() const; -typedef const char* TName; -typedef const char* TUnit; - -static TUnit aUnit[3] = {"m","m","m"}; - -static TGetCoord aXYZGetCoord[3] = { - &SMDS_MeshNode::X, - &SMDS_MeshNode::Y, - &SMDS_MeshNode::Z -}; -static TName aXYZName[3] = {"x","y","z"}; - - -static TGetCoord aXYGetCoord[2] = { - &SMDS_MeshNode::X, - &SMDS_MeshNode::Y -}; -static TName aXYName[2] = {"x","y"}; - -static TGetCoord aYZGetCoord[2] = { - &SMDS_MeshNode::Y, - &SMDS_MeshNode::Z -}; -static TName aYZName[2] = {"y","z"}; - -static TGetCoord aXZGetCoord[2] = { - &SMDS_MeshNode::X, - &SMDS_MeshNode::Z -}; -static TName aXZName[2] = {"x","z"}; - - -static TGetCoord aXGetCoord[1] = { - &SMDS_MeshNode::X -}; -static TName aXName[1] = {"x"}; - -static TGetCoord aYGetCoord[1] = { - &SMDS_MeshNode::Y -}; -static TName aYName[1] = {"y"}; - -static TGetCoord aZGetCoord[1] = { - &SMDS_MeshNode::Z -}; -static TName aZName[1] = {"z"}; - - -class TCoordHelper{ - SMDS_NodeIteratorPtr myNodeIter; - const SMDS_MeshNode* myCurrentNode; - TGetCoord* myGetCoord; - TName* myName; - TUnit* myUnit; -public: - TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter, - TGetCoord* theGetCoord, - TName* theName, - TUnit* theUnit = aUnit): - myNodeIter(theNodeIter), - myGetCoord(theGetCoord), - myName(theName), - myUnit(theUnit) - {} - virtual ~TCoordHelper(){} - bool Next(){ - return myNodeIter->more() && - (myCurrentNode = myNodeIter->next()); - } - const SMDS_MeshNode* GetNode(){ - return myCurrentNode; - } - MED::TIntVector::value_type GetID(){ - return myCurrentNode->GetID(); - } - MED::TFloatVector::value_type GetCoord(med_int theCoodId){ - return (myCurrentNode->*myGetCoord[theCoodId])(); - } - MED::TStringVector::value_type GetName(med_int theDimId){ - return myName[theDimId]; - } - MED::TStringVector::value_type GetUnit(med_int theDimId){ - return myUnit[theDimId]; - } -}; -typedef boost::shared_ptr TCoordHelperPtr; - +namespace{ + typedef double (SMDS_MeshNode::* TGetCoord)() const; + typedef const char* TName; + typedef const char* TUnit; + + TUnit aUnit[3] = {"m","m","m"}; + + TGetCoord aXYZGetCoord[3] = { + &SMDS_MeshNode::X, + &SMDS_MeshNode::Y, + &SMDS_MeshNode::Z + }; + TName aXYZName[3] = {"x","y","z"}; + + + TGetCoord aXYGetCoord[2] = { + &SMDS_MeshNode::X, + &SMDS_MeshNode::Y + }; + TName aXYName[2] = {"x","y"}; + + TGetCoord aYZGetCoord[2] = { + &SMDS_MeshNode::Y, + &SMDS_MeshNode::Z + }; + TName aYZName[2] = {"y","z"}; + + TGetCoord aXZGetCoord[2] = { + &SMDS_MeshNode::X, + &SMDS_MeshNode::Z + }; + TName aXZName[2] = {"x","z"}; + + + TGetCoord aXGetCoord[1] = { + &SMDS_MeshNode::X + }; + TName aXName[1] = {"x"}; + + TGetCoord aYGetCoord[1] = { + &SMDS_MeshNode::Y + }; + TName aYName[1] = {"y"}; + + TGetCoord aZGetCoord[1] = { + &SMDS_MeshNode::Z + }; + TName aZName[1] = {"z"}; + + + class TCoordHelper{ + SMDS_NodeIteratorPtr myNodeIter; + const SMDS_MeshNode* myCurrentNode; + TGetCoord* myGetCoord; + TName* myName; + TUnit* myUnit; + public: + TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter, + TGetCoord* theGetCoord, + TName* theName, + TUnit* theUnit = aUnit): + myNodeIter(theNodeIter), + myGetCoord(theGetCoord), + myName(theName), + myUnit(theUnit) + {} + virtual ~TCoordHelper(){} + bool Next(){ + return myNodeIter->more() && + (myCurrentNode = myNodeIter->next()); + } + const SMDS_MeshNode* GetNode(){ + return myCurrentNode; + } + MED::TIntVector::value_type GetID(){ + return myCurrentNode->GetID(); + } + MED::TFloatVector::value_type GetCoord(TInt theCoodId){ + return (myCurrentNode->*myGetCoord[theCoodId])(); + } + MED::TStringVector::value_type GetName(TInt theDimId){ + return myName[theDimId]; + } + MED::TStringVector::value_type GetUnit(TInt theDimId){ + return myUnit[theDimId]; + } + }; + typedef boost::shared_ptr TCoordHelperPtr; + +} + Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() { Status aResult = DRS_OK; @@ -188,11 +204,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() return DRS_FAIL; } try{ - using namespace MEDA; - using namespace boost; - MESSAGE("Perform - myFile : "< EPS; anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS; anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS; - aMeshDimension = anIsXDimension + anIsYDimension + anIsZDimension; if(!aMeshDimension) aMeshDimension = 3; @@ -268,9 +279,9 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() } - PMeshInfo aMeshInfo = TWrapper::CrMeshInfo(aMeshDimension,aMeshName); + PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aMeshName); MESSAGE("Add - aMeshName : "<GetName()); - aMed.SetMeshInfo(aMeshInfo); + myMed->SetMeshInfo(aMeshInfo); // Storing SMDS groups and sub-meshes //----------------------------------- @@ -303,8 +314,8 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() for (; aFamsIter != aFamilies.end(); aFamsIter++) { - PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(aMeshInfo); - aMed.SetFamilyInfo(aFamilyInfo); + PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo); + myMed->SetFamilyInfo(aFamilyInfo); int aFamId = (*aFamsIter)->GetId(); const set& anElems = (*aFamsIter)->GetElements(); @@ -319,15 +330,15 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() // Storing SMDS nodes to the MED file for the MED mesh //---------------------------------------------------- #ifdef _EDF_NODE_IDS_ - typedef map TNodeIdMap; + typedef map TNodeIdMap; TNodeIdMap aNodeIdMap; #endif - med_int aNbElems = myMesh->NbNodes(); + TInt aNbElems = myMesh->NbNodes(); MED::TIntVector anElemNums(aNbElems); MED::TIntVector aFamilyNums(aNbElems); MED::TFloatVector aCoordinates(aNbElems*aMeshDimension); - for(med_int iNode = 0, aStartId = 0; aCoordHelperPtr->Next(); iNode++, aStartId += aMeshDimension){ - for(med_int iCoord = 0; iCoord < aMeshDimension; iCoord++){ + for(TInt iNode = 0, aStartId = 0; aCoordHelperPtr->Next(); iNode++, aStartId += aMeshDimension){ + for(TInt iCoord = 0; iCoord < aMeshDimension; iCoord++){ aCoordinates[aStartId+iCoord] = aCoordHelperPtr->GetCoord(iCoord); } int aNodeID = aCoordHelperPtr->GetID(); @@ -344,44 +355,44 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() MED::TStringVector aCoordNames(aMeshDimension); MED::TStringVector aCoordUnits(aMeshDimension); - for(med_int iCoord = 0; iCoord < aMeshDimension; iCoord++){ + for(TInt iCoord = 0; iCoord < aMeshDimension; iCoord++){ aCoordNames[iCoord] = aCoordHelperPtr->GetName(iCoord); aCoordUnits[iCoord] = aCoordHelperPtr->GetUnit(iCoord); } - const med_repere SMDS_COORDINATE_SYSTEM = MED_CART; + const ERepere SMDS_COORDINATE_SYSTEM = eCART; - PNodeInfo aNodeInfo = TWrapper::CrNodeInfo(aMeshInfo, - SMDS_COORDINATE_SYSTEM, - aCoordinates, - aCoordNames, - aCoordUnits, - aFamilyNums, - anElemNums); + PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, + SMDS_COORDINATE_SYSTEM, + aCoordinates, + aCoordNames, + aCoordUnits, + aFamilyNums, + anElemNums); MESSAGE("Perform - aNodeInfo->GetNbElem() = "<SetNodeInfo(aNodeInfo); // Storing others SMDS elements to the MED file for the MED mesh //-------------------------------------------------------------- - med_entite_maillage SMDS_MED_ENTITY = MED_MAILLE; - const med_connectivite SMDS_MED_CONNECTIVITY = MED_NOD; + EEntiteMaillage SMDS_MED_ENTITY = eMAILLE; + const EConnectivite SMDS_MED_CONNECTIVITY = eNOD; // Storing SMDS Edges - if(med_int aNbElems = myMesh->NbEdges()){ + if(TInt aNbElems = myMesh->NbEdges()){ #ifdef _ELEMENTS_BY_DIM_ - SMDS_MED_ENTITY = MED_ARETE; + SMDS_MED_ENTITY = eARETE; #endif SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator(); - med_int aNbConnectivity = MED::GetNbConn(SMDS_MED_ENTITY,MED_SEG2,aMeshDimension); + TInt aNbConnectivity = MED::GetNbConn(SMDS_MED_ENTITY,eSEG2,aMeshDimension); MED::TIntVector anElemNums(aNbElems); MED::TIntVector aFamilyNums(aNbElems); MED::TIntVector aConnectivity(aNbElems*aNbConnectivity); - for(med_int iElem = 0, iConn = 0; anIter->more(); iElem++, iConn+=aNbConnectivity){ + for(TInt iElem = 0, iConn = 0; anIter->more(); iElem++, iConn+=aNbConnectivity){ const SMDS_MeshEdge* anElem = anIter->next(); SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator(); - for(med_int iNode = 0; iNode < aNbConnectivity && aNodesIter->more(); iNode++){ + for(TInt iNode = 0; iNode < aNbConnectivity && aNodesIter->more(); iNode++){ const SMDS_MeshElement* aNode = aNodesIter->next(); #ifdef _EDF_NODE_IDS_ aConnectivity[iConn+iNode] = aNodeIdMap[aNode->GetID()]; @@ -397,23 +408,23 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() aFamilyNums[iElem] = myEdgesDefaultFamilyId; } - PCellInfo aCellInfo = TWrapper::CrCellInfo(aMeshInfo, - SMDS_MED_ENTITY, - MED_SEG2, - SMDS_MED_CONNECTIVITY, - aConnectivity, - aFamilyNums, - anElemNums); - aMed.SetCellInfo(aCellInfo); + PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo, + SMDS_MED_ENTITY, + eSEG2, + SMDS_MED_CONNECTIVITY, + aConnectivity, + aFamilyNums, + anElemNums); + myMed->SetCellInfo(aCellInfo); } // Storing SMDS Faces - if(med_int aNbElems = myMesh->NbFaces()){ + if(TInt aNbElems = myMesh->NbFaces()){ SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); #ifdef _ELEMENTS_BY_DIM_ - SMDS_MED_ENTITY = MED_FACE; + SMDS_MED_ENTITY = eFACE; #endif - med_int aNbTriaConn = MED::GetNbConn(SMDS_MED_ENTITY,MED_TRIA3,aMeshDimension); + TInt aNbTriaConn = MED::GetNbConn(SMDS_MED_ENTITY,eTRIA3,aMeshDimension); MED::TIntVector anTriaElemNums; anTriaElemNums.reserve(aNbElems); MED::TIntVector aTriaFamilyNums; @@ -421,7 +432,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() MED::TIntVector aTriaConn; aTriaConn.reserve(aNbElems*aNbTriaConn); - med_int aNbQuadConn = MED::GetNbConn(SMDS_MED_ENTITY,MED_QUAD4,aMeshDimension); + TInt aNbQuadConn = MED::GetNbConn(SMDS_MED_ENTITY,eQUAD4,aMeshDimension); MED::TIntVector aQuadElemNums; aQuadElemNums.reserve(aNbElems); MED::TIntVector aQuadFamilyNums; @@ -429,11 +440,11 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() MED::TIntVector aQuadConn; aQuadConn.reserve(aNbElems*aNbQuadConn); - for(med_int iElem = 0; iElem < aNbElems && anIter->more(); iElem++){ + for(TInt iElem = 0; iElem < aNbElems && anIter->more(); iElem++){ const SMDS_MeshFace* anElem = anIter->next(); - med_int aNbNodes = anElem->NbNodes(); + TInt aNbNodes = anElem->NbNodes(); SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator(); - med_int aNbConnectivity; + TInt aNbConnectivity; MED::TIntVector* anElemNums; MED::TIntVector* aFamilyNums; MED::TIntVector* aConnectivity; @@ -452,12 +463,12 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() break; } MED::TIntVector aVector(aNbNodes); - for(med_int iNode = 0; aNodesIter->more(); iNode++){ + for(TInt iNode = 0; aNodesIter->more(); iNode++){ const SMDS_MeshElement* aNode = aNodesIter->next(); aVector[iNode] = aNode->GetID(); } - med_int aSize = aConnectivity->size(); + TInt aSize = aConnectivity->size(); aConnectivity->resize(aSize+aNbConnectivity); // There is some differnce between SMDS and MED in cells mapping #ifdef _EDF_NODE_IDS_ @@ -468,7 +479,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() (*aConnectivity)[aSize+2] = aNodeIdMap[aVector[3]]; (*aConnectivity)[aSize+3] = aNodeIdMap[aVector[2]]; default: - for(med_int iNode = 0; iNode < aNbNodes; iNode++) + for(TInt iNode = 0; iNode < aNbNodes; iNode++) (*aConnectivity)[aSize+iNode] = aNodeIdMap[aVector[iNode]]; } #else @@ -479,7 +490,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() (*aConnectivity)[aSize+2] = aVector[3]; (*aConnectivity)[aSize+3] = aVector[2]; default: - for(med_int iNode = 0; iNode < aNbNodes; iNode++) + for(TInt iNode = 0; iNode < aNbNodes; iNode++) (*aConnectivity)[aSize+iNode] = aVector[iNode]; } #endif @@ -490,37 +501,37 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() else aFamilyNums->push_back(myFacesDefaultFamilyId); } - if(med_int aNbElems = anTriaElemNums.size()){ - PCellInfo aCellInfo = TWrapper::CrCellInfo(aMeshInfo, - SMDS_MED_ENTITY, - MED_TRIA3, - SMDS_MED_CONNECTIVITY, - aTriaConn, - aTriaFamilyNums, - anTriaElemNums); - MESSAGE("Perform - anEntity = "< #include @@ -43,6 +44,9 @@ class DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh DriverMED_W_SMESHDS_Mesh(); + virtual void SetFile(const std::string& theFileName); + void SetFile(const std::string& theFileName, MED::EVersion theId); + /*! sets file name; only for usage with Add(), not Write() */ void AddGroupOfNodes(); @@ -63,6 +67,7 @@ class DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh private: + MED::PWrapper myMed; std::string myMeshName; std::list myGroups; bool myAllSubMeshes; diff --git a/src/DriverMED/Makefile.in b/src/DriverMED/Makefile.in index beca72c92..19d97d9ac 100644 --- a/src/DriverMED/Makefile.in +++ b/src/DriverMED/Makefile.in @@ -60,7 +60,7 @@ LIB_SERVER_IDL = # additionnal information to compil and link file CPPFLAGS += $(OCC_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome $(BOOST_CPPFLAGS) -CXXFLAGS += $(OCC_CXXFLAGS) $(MED2_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome +CXXFLAGS += $(OCC_CXXFLAGS) $(HDF5_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome LDFLAGS += -lMeshDriver -L${KERNEL_ROOT_DIR}/lib/salome -lMEDWrapper LDFLAGSFORBIN += -lMeshDriver -lSMDS -lSMESHDS -L${KERNEL_ROOT_DIR}/lib/salome -lMEDWrapper -lOpUtil -lSALOMELocalTrace diff --git a/src/DriverUNV/Makefile.in b/src/DriverUNV/Makefile.in index 8d6bac47e..a0ab5b714 100644 --- a/src/DriverUNV/Makefile.in +++ b/src/DriverUNV/Makefile.in @@ -61,9 +61,9 @@ LIB_CLIENT_IDL = LIB_SERVER_IDL = # additionnal information to compil and link file -CPPFLAGS += -I${KERNEL_ROOT_DIR}/include/salome $(BOOST_CPPFLAGS) +CPPFLAGS += -I${KERNEL_ROOT_DIR}/include/salome $(OCC_INCLUDES) $(BOOST_CPPFLAGS) CXXFLAGS += -I${KERNEL_ROOT_DIR}/include/salome -LDFLAGS += -lMeshDriver +LDFLAGS += -lMeshDriver $(OCC_KERNEL_LIBS) LDFLAGSFORBIN += -lMeshDriver -lSMDS -L${KERNEL_ROOT_DIR}/lib/salome -lOpUtil -lSALOMELocalTrace diff --git a/src/OBJECT/Makefile.in b/src/OBJECT/Makefile.in index 46b6224af..bc91acb4a 100644 --- a/src/OBJECT/Makefile.in +++ b/src/OBJECT/Makefile.in @@ -31,7 +31,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl:$(top_builddir)/idl @COMMENCE@ -EXPORT_HEADERS = SMESH_Actor.h SMESH_Object.h SMESH_ActorUtils.h +EXPORT_HEADERS = SMESH_Actor.h SMESH_Object.h SMESH_ObjectDef.h SMESH_ActorUtils.h # Libraries targets diff --git a/src/OBJECT/SMESH_Actor.cxx b/src/OBJECT/SMESH_Actor.cxx index 5d80d26fa..b3802aefb 100644 --- a/src/OBJECT/SMESH_Actor.cxx +++ b/src/OBJECT/SMESH_Actor.cxx @@ -27,13 +27,13 @@ // $Header$ -#include "SMESH_Actor.h" +#include "SMESH_ActorDef.h" #include "SMESH_ActorUtils.h" #include "SMESH_DeviceActor.h" +#include "SMESH_ControlsDef.hxx" #include "SALOME_ExtractUnstructuredGrid.h" #include "QAD_Config.h" -#include "utilities.h" #include #include @@ -69,20 +69,20 @@ #include #include +#include "utilities.h" + #ifdef _DEBUG_ static int MYDEBUG = 0; -static int MYDEBUGWITHFILES = 0; #else static int MYDEBUG = 0; -static int MYDEBUGWITHFILES = 0; #endif static int aLineWidthInc = 2; static int aPointSizeInc = 2; -SMESH_Actor* SMESH_Actor::New(){ - return new SMESH_Actor(); +SMESH_ActorDef* SMESH_ActorDef::New(){ + return new SMESH_ActorDef(); } @@ -91,7 +91,7 @@ SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj, const char* theName, int theIsClear) { - SMESH_Actor* anActor = SMESH_Actor::New(); + SMESH_ActorDef* anActor = SMESH_ActorDef::New(); if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){ anActor->Delete(); anActor = NULL; @@ -100,8 +100,8 @@ SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj, } -SMESH_Actor::SMESH_Actor(){ - if(MYDEBUG) MESSAGE("SMESH_Actor"); +SMESH_ActorDef::SMESH_ActorDef(){ + if(MYDEBUG) MESSAGE("SMESH_ActorDef"); myTimeStamp = vtkTimeStamp::New(); @@ -284,8 +284,7 @@ SMESH_Actor::SMESH_Actor(){ myName = ""; myIO = NULL; - myColorMode = eNone; - my1DColorMode = e1DNone; + myControlMode = eNone; myControlActor = my2DActor; //Definition of myScalarBarActor @@ -438,7 +437,9 @@ SMESH_Actor::SMESH_Actor(){ aPtsTextProp->SetShadow(0); myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp); aPtsTextProp->Delete(); - + + myEntityMode = eAllEntity; + myIsPointsLabeled = false; myPointLabels = vtkActor2D::New(); @@ -491,8 +492,8 @@ SMESH_Actor::SMESH_Actor(){ } -SMESH_Actor::~SMESH_Actor(){ - if(MYDEBUG) MESSAGE("~SMESH_Actor"); +SMESH_ActorDef::~SMESH_ActorDef(){ + if(MYDEBUG) MESSAGE("~SMESH_ActorDef"); myScalarBarActor->Delete(); myLookupTable->Delete(); @@ -562,7 +563,7 @@ SMESH_Actor::~SMESH_Actor(){ } -void SMESH_Actor::SetPointsLabeled( bool theIsPointsLabeled ) +void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled ) { vtkUnstructuredGrid* aGrid = GetUnstructuredGrid(); myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints(); @@ -597,7 +598,7 @@ void SMESH_Actor::SetPointsLabeled( bool theIsPointsLabeled ) } -void SMESH_Actor::SetCellsLabeled(bool theIsCellsLabeled){ +void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled){ vtkUnstructuredGrid* aGrid = GetUnstructuredGrid(); myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints(); if(myIsCellsLabeled){ @@ -620,9 +621,8 @@ void SMESH_Actor::SetCellsLabeled(bool theIsCellsLabeled){ } -void SMESH_Actor::SetControlMode(eControl theMode){ - myColorMode = eNone; - my1DColorMode = e1DNone; +void SMESH_ActorDef::SetControlMode(eControl theMode){ + myControlMode = eNone; my1DActor->GetMapper()->SetScalarVisibility(false); my2DActor->GetMapper()->SetScalarVisibility(false); @@ -634,7 +634,7 @@ void SMESH_Actor::SetControlMode(eControl theMode){ if(anIsScalarVisible){ SMESH::Controls::FunctorPtr aFunctor; switch(theMode){ - case eLengthEdges: + case eLength: { SMESH::Controls::Length* aControl = new SMESH::Controls::Length(); aControl->SetPrecision( myControlsPrecision ); @@ -642,6 +642,12 @@ void SMESH_Actor::SetControlMode(eControl theMode){ myControlActor = my1DActor; break; } + case eLength2D: + { + aFunctor.reset(new SMESH::Controls::Length2D()); + myControlActor = my2DActor; + break; + } case eFreeBorders: aFunctor.reset(new SMESH::Controls::FreeBorders()); myControlActor = my1DActor; @@ -654,6 +660,10 @@ void SMESH_Actor::SetControlMode(eControl theMode){ aFunctor.reset(new SMESH::Controls::MultiConnection()); myControlActor = my1DActor; break; + case eMultiConnection2D: + aFunctor.reset(new SMESH::Controls::MultiConnection2D()); + myControlActor = my2DActor; + break; case eArea: { SMESH::Controls::Area* aControl = new SMESH::Controls::Area(); @@ -678,6 +688,14 @@ void SMESH_Actor::SetControlMode(eControl theMode){ myControlActor = my2DActor; break; } + case eAspectRatio3D: + { + SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D(); + aControl->SetPrecision( myControlsPrecision ); + aFunctor.reset( aControl ); + myControlActor = my3DActor; + break; + } case eMinimumAngle: { SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle(); @@ -709,17 +727,36 @@ void SMESH_Actor::SetControlMode(eControl theMode){ vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid(); vtkIdType aNbCells = aGrid->GetNumberOfCells(); if(aNbCells){ - myColorMode = theMode; - if(theMode == eFreeBorders || theMode == eFreeEdges){ - my1DColorMode = e1DHighlited; + myControlMode = theMode; + switch(myControlMode){ + case eFreeEdges: + case eFreeBorders: my1DExtActor->SetExtControlMode(aFunctor,myControlActor); - }else{ - if(myControlActor == my1DActor) - my1DColorMode = e1DColored; + break; + case eLength2D: + my1DExtActor->SetExtControlMode(aFunctor,myControlActor,myScalarBarActor,myLookupTable); + break; + case eMultiConnection2D: + my1DExtActor->SetExtControlMode(aFunctor,myControlActor,myScalarBarActor,myLookupTable); + break; + default: myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable); } } + + if(QAD_CONFIG->getSetting("SMESH:DispayEntity") == "true"){ + if(myControlActor == my1DActor) + myEntityMode = eEdges; + else if(myControlActor == my2DActor) + myEntityMode = eFaces; + else if(myControlActor == my3DActor) + myEntityMode = eVolumes; + } + + }else if(QAD_CONFIG->getSetting("SMESH:DispayEntity") == "true"){ + myEntityMode = eAllEntity; } + SetRepresentation(GetRepresentation()); myTimeStamp->Modified(); @@ -727,7 +764,7 @@ void SMESH_Actor::SetControlMode(eControl theMode){ } -void SMESH_Actor::AddToRender(vtkRenderer* theRenderer){ +void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){ SALOME_Actor::AddToRender(theRenderer); theRenderer->AddActor(myNodeActor); @@ -751,7 +788,7 @@ void SMESH_Actor::AddToRender(vtkRenderer* theRenderer){ theRenderer->AddActor2D(myCellsLabels); } -void SMESH_Actor::RemoveFromRender(vtkRenderer* theRenderer){ +void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){ SALOME_Actor::RemoveFromRender(theRenderer); theRenderer->RemoveActor(myNodeActor); @@ -772,10 +809,10 @@ void SMESH_Actor::RemoveFromRender(vtkRenderer* theRenderer){ } -bool SMESH_Actor::Init(TVisualObjPtr theVisualObj, - const char* theEntry, - const char* theName, - int theIsClear) +bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj, + const char* theEntry, + const char* theName, + int theIsClear) { Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName); setIO(anIO); @@ -809,6 +846,8 @@ bool SMESH_Actor::Init(TVisualObjPtr theVisualObj, my3DActor->Init(myVisualObj,myImplicitBoolean); my1DActor->GetMapper()->SetLookupTable(myLookupTable); + my1DExtActor->GetMapper()->SetLookupTable(myLookupTable); + my2DActor->GetMapper()->SetLookupTable(myLookupTable); my3DActor->GetMapper()->SetLookupTable(myLookupTable); @@ -840,17 +879,17 @@ bool SMESH_Actor::Init(TVisualObjPtr theVisualObj, } -float* SMESH_Actor::GetBounds(){ +float* SMESH_ActorDef::GetBounds(){ return myNodeActor->GetBounds(); } -vtkDataSet* SMESH_Actor::GetInput(){ +vtkDataSet* SMESH_ActorDef::GetInput(){ return GetUnstructuredGrid(); } -void SMESH_Actor::SetTransform(SALOME_Transform* theTransform){ +void SMESH_ActorDef::SetTransform(SALOME_Transform* theTransform){ myNodeActor->SetTransform(theTransform); myBaseActor->SetTransform(theTransform); @@ -867,27 +906,27 @@ void SMESH_Actor::SetTransform(SALOME_Transform* theTransform){ } -void SMESH_Actor::SetMapper(vtkMapper* theMapper){ +void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){ vtkLODActor::SetMapper(theMapper); } -void SMESH_Actor::ShallowCopy(vtkProp *prop){ +void SMESH_ActorDef::ShallowCopy(vtkProp *prop){ SALOME_Actor::ShallowCopy(prop); } -vtkMapper* SMESH_Actor::GetMapper(){ +vtkMapper* SMESH_ActorDef::GetMapper(){ return myPickableActor->GetMapper(); } -vtkUnstructuredGrid* SMESH_Actor::GetUnstructuredGrid(){ +vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){ return myVisualObj->GetUnstructuredGrid(); } -bool SMESH_Actor::IsInfinitive(){ +bool SMESH_ActorDef::IsInfinitive(){ vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid(); aDataSet->Update(); myIsInfinite = aDataSet->GetNumberOfCells() == 0 || @@ -897,16 +936,16 @@ bool SMESH_Actor::IsInfinitive(){ } -void SMESH_Actor::SetIsShrunkable(bool theShrunkable){ +void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){ myIsShrinkable = theShrunkable; Modified(); } -float SMESH_Actor::GetShrinkFactor(){ +float SMESH_ActorDef::GetShrinkFactor(){ return myBaseActor->GetShrinkFactor(); } -void SMESH_Actor::SetShrinkFactor(float theValue){ +void SMESH_ActorDef::SetShrinkFactor(float theValue){ myBaseActor->SetShrinkFactor(theValue); my1DActor->SetShrinkFactor(theValue); @@ -918,7 +957,7 @@ void SMESH_Actor::SetShrinkFactor(float theValue){ Modified(); } -void SMESH_Actor::SetShrink(){ +void SMESH_ActorDef::SetShrink(){ if(!myIsShrinkable) return; myBaseActor->SetShrink(); @@ -933,7 +972,7 @@ void SMESH_Actor::SetShrink(){ Modified(); } -void SMESH_Actor::UnShrink(){ +void SMESH_ActorDef::UnShrink(){ if(!myIsShrunk) return; myBaseActor->UnShrink(); @@ -949,74 +988,110 @@ void SMESH_Actor::UnShrink(){ } -int SMESH_Actor::GetNodeObjId(int theVtkID){ +int SMESH_ActorDef::GetNodeObjId(int theVtkID){ return myPickableActor->GetNodeObjId(theVtkID); } -float* SMESH_Actor::GetNodeCoord(int theObjID){ +float* SMESH_ActorDef::GetNodeCoord(int theObjID){ return myPickableActor->GetNodeCoord(theObjID); } -int SMESH_Actor::GetElemObjId(int theVtkID){ +int SMESH_ActorDef::GetElemObjId(int theVtkID){ return myPickableActor->GetElemObjId(theVtkID); } -vtkCell* SMESH_Actor::GetElemCell(int theObjID){ +vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){ return myPickableActor->GetElemCell(theObjID); } -void SMESH_Actor::SetVisibility(int theMode){ +void SMESH_ActorDef::SetVisibility(int theMode){ SetVisibility(theMode,true); } -void SMESH_Actor::SetVisibility(int theMode, bool theIsUpdateRepersentation){ +void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){ SALOME_Actor::SetVisibility(theMode); + + myNodeActor->VisibilityOff(); + myBaseActor->VisibilityOff(); + + my1DActor->VisibilityOff(); + my1DExtActor->VisibilityOff(); + + my2DActor->VisibilityOff(); + my3DActor->VisibilityOff(); + + myScalarBarActor->VisibilityOff(); + myPointLabels->VisibilityOff(); + myCellsLabels->VisibilityOff(); + if(GetVisibility()){ if(theIsUpdateRepersentation) SetRepresentation(GetRepresentation()); - if(myColorMode != eNone){ - if(my1DColorMode == e1DHighlited) + if(myControlMode != eNone){ + switch(myControlMode){ + case eFreeEdges: + case eFreeBorders: + my1DExtActor->VisibilityOn(); + break; + case eLength2D: my1DExtActor->VisibilityOn(); - else if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells()) - myScalarBarActor->VisibilityOn(); + case eMultiConnection2D: + my1DExtActor->VisibilityOn(); + default: + if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells()) + myScalarBarActor->VisibilityOn(); + } } if(myRepresentation != ePoint) myPickableActor->VisibilityOn(); - my1DActor->VisibilityOn(); + if(myEntityMode & eEdges) + my1DActor->VisibilityOn(); + + if(myEntityMode & eFaces) + my2DActor->VisibilityOn(); + + if(myEntityMode & eVolumes) + my3DActor->VisibilityOn(); + + if(myIsPointsLabeled) + myPointLabels->VisibilityOn(); - my2DActor->VisibilityOn(); - my3DActor->VisibilityOn(); + if(myIsCellsLabeled) + myCellsLabels->VisibilityOn(); + } - if(myIsPointsLabeled) myPointLabels->VisibilityOn(); - if(myIsCellsLabeled) myCellsLabels->VisibilityOn(); - }else{ - myNodeActor->VisibilityOff(); - myBaseActor->VisibilityOff(); + Modified(); +} - my1DActor->VisibilityOff(); - my1DExtActor->VisibilityOff(); - my2DActor->VisibilityOff(); - my3DActor->VisibilityOff(); +void SMESH_ActorDef::SetEntityMode(unsigned int theMode){ + if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)) + theMode &= ~eEdges; - myScalarBarActor->VisibilityOff(); - myPointLabels->VisibilityOff(); - myCellsLabels->VisibilityOff(); - } - Modified(); -} + if(!myVisualObj->GetNbEntities(SMDSAbs_Face)) + theMode &= ~eFaces; + + if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)) + theMode &= ~eVolumes; + if(!theMode) + return; -void SMESH_Actor::SetRepresentation(int theMode){ - int aNbEdges = myVisualObj->GetNbEntities(SMESH::EDGE); - int aNbFaces = myVisualObj->GetNbEntities(SMESH::FACE); - int aNbVolumes = myVisualObj->GetNbEntities(SMESH::VOLUME); + myEntityMode = theMode; + + SetVisibility(GetVisibility(),false); +} + +void SMESH_ActorDef::SetRepresentation(int theMode){ + int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge); + int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face); + int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume); if(theMode < 0){ myRepresentation = eSurface; if(!aNbFaces && !aNbVolumes && aNbEdges){ @@ -1080,15 +1155,14 @@ void SMESH_Actor::SetRepresentation(int theMode){ my3DActor->SetRepresentation(aReperesent); my1DExtActor->SetVisibility(false); - switch(my1DColorMode){ - case e1DColored: + + switch(myControlMode){ + case eLength: + case eMultiConnection: aProp = aBackProp = my1DProp; if(myRepresentation != ePoint) aReperesent = SMESH_DeviceActor::eInsideframe; break; - case e1DHighlited: - my1DExtActor->SetVisibility(true); - break; } my1DActor->SetProperty(aProp); @@ -1111,17 +1185,17 @@ void SMESH_Actor::SetRepresentation(int theMode){ } -void SMESH_Actor::SetPointRepresentation(bool theIsPointsVisible){ +void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){ myIsPointsVisible = theIsPointsVisible; SetRepresentation(GetRepresentation()); } -bool SMESH_Actor::GetPointRepresentation(){ +bool SMESH_ActorDef::GetPointRepresentation(){ return myIsPointsVisible || myIsPointsLabeled; } -void SMESH_Actor::UpdateHighlight(){ +void SMESH_ActorDef::UpdateHighlight(){ myHighlitableActor->SetVisibility(false); myHighlitableActor->SetHighlited(false); @@ -1151,20 +1225,20 @@ void SMESH_Actor::UpdateHighlight(){ } -void SMESH_Actor::highlight(bool theHighlight){ +void SMESH_ActorDef::highlight(bool theHighlight){ myIsHighlighted = theHighlight; UpdateHighlight(); } -void SMESH_Actor::SetPreSelected(bool thePreselect){ +void SMESH_ActorDef::SetPreSelected(bool thePreselect){ myIsPreselected = thePreselect; UpdateHighlight(); } // From vtkFollower -int SMESH_Actor::RenderOpaqueGeometry(vtkViewport *vp) +int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp) { if (myPickableActor->GetIsOpaque()) { @@ -1176,7 +1250,7 @@ int SMESH_Actor::RenderOpaqueGeometry(vtkViewport *vp) } -int SMESH_Actor::RenderTranslucentGeometry(vtkViewport *vp) +int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp) { if (!myPickableActor->GetIsOpaque()) { @@ -1188,42 +1262,35 @@ int SMESH_Actor::RenderTranslucentGeometry(vtkViewport *vp) } -void SMESH_Actor::Render(vtkRenderer *ren){ - unsigned long mTime = myTimeStamp->GetMTime(); +void SMESH_ActorDef::Render(vtkRenderer *ren){ + unsigned long aTime = myTimeStamp->GetMTime(); unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime(); - if(anObjTime > mTime) + unsigned long aClippingTime = myImplicitBoolean->GetMTime(); + if(anObjTime > aTime || aClippingTime > aTime) Update(); } -void SMESH_Actor::Update(){ - SetVisibility(GetVisibility()); - unsigned long int anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime(); - unsigned long int aClippingTime = myImplicitBoolean->GetMTime(); - unsigned long int aTime = myTimeStamp->GetMTime(); - if(MYDEBUG) MESSAGE("SMESH_Actor::Update"); +void SMESH_ActorDef::Update(){ + if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update"); if(GetControlMode() != eNone) { - if(anObjTime > aTime || aClippingTime > aTime){ - SetControlMode(GetControlMode()); - SetVisibility(GetVisibility()); - } + SetControlMode(GetControlMode()); } if(myIsPointsLabeled){ - if(anObjTime > aTime || aClippingTime > aTime) - SetPointsLabeled(myIsPointsLabeled); + SetPointsLabeled(myIsPointsLabeled); } if(myIsCellsLabeled){ - if(anObjTime > aTime || aClippingTime > aTime) - SetCellsLabeled(myIsCellsLabeled); + SetCellsLabeled(myIsCellsLabeled); } - + SetVisibility(GetVisibility()); + myTimeStamp->Modified(); Modified(); } -void SMESH_Actor::ReleaseGraphicsResources(vtkWindow *renWin){ +void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){ SALOME_Actor::ReleaseGraphicsResources(renWin); myPickableActor->ReleaseGraphicsResources(renWin); @@ -1238,7 +1305,7 @@ static void GetColor(vtkProperty *theProperty, float& r,float& g,float& b){ } -void SMESH_Actor::SetOpacity(float theValue){ +void SMESH_ActorDef::SetOpacity(float theValue){ mySurfaceProp->SetOpacity(theValue); myBackSurfaceProp->SetOpacity(theValue); myEdgeProp->SetOpacity(theValue); @@ -1248,74 +1315,74 @@ void SMESH_Actor::SetOpacity(float theValue){ } -float SMESH_Actor::GetOpacity(){ +float SMESH_ActorDef::GetOpacity(){ return mySurfaceProp->GetOpacity(); } -void SMESH_Actor::SetSufaceColor(float r,float g,float b){ +void SMESH_ActorDef::SetSufaceColor(float r,float g,float b){ mySurfaceProp->SetColor(r,g,b); Modified(); } -void SMESH_Actor::GetSufaceColor(float& r,float& g,float& b){ +void SMESH_ActorDef::GetSufaceColor(float& r,float& g,float& b){ ::GetColor(mySurfaceProp,r,g,b); } -void SMESH_Actor::SetBackSufaceColor(float r,float g,float b){ +void SMESH_ActorDef::SetBackSufaceColor(float r,float g,float b){ myBackSurfaceProp->SetColor(r,g,b); Modified(); } -void SMESH_Actor::GetBackSufaceColor(float& r,float& g,float& b){ +void SMESH_ActorDef::GetBackSufaceColor(float& r,float& g,float& b){ ::GetColor(myBackSurfaceProp,r,g,b); } -void SMESH_Actor::SetEdgeColor(float r,float g,float b){ +void SMESH_ActorDef::SetEdgeColor(float r,float g,float b){ myEdgeProp->SetColor(r,g,b); my1DProp->SetColor(r,g,b); my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b); Modified(); } -void SMESH_Actor::GetEdgeColor(float& r,float& g,float& b){ +void SMESH_ActorDef::GetEdgeColor(float& r,float& g,float& b){ ::GetColor(myEdgeProp,r,g,b); } -void SMESH_Actor::SetNodeColor(float r,float g,float b){ +void SMESH_ActorDef::SetNodeColor(float r,float g,float b){ myNodeProp->SetColor(r,g,b); Modified(); } -void SMESH_Actor::GetNodeColor(float& r,float& g,float& b){ +void SMESH_ActorDef::GetNodeColor(float& r,float& g,float& b){ ::GetColor(myNodeProp,r,g,b); } -void SMESH_Actor::SetHighlightColor(float r,float g,float b){ +void SMESH_ActorDef::SetHighlightColor(float r,float g,float b){ myHighlightProp->SetColor(r,g,b); Modified(); } -void SMESH_Actor::GetHighlightColor(float& r,float& g,float& b){ +void SMESH_ActorDef::GetHighlightColor(float& r,float& g,float& b){ ::GetColor(myHighlightProp,r,g,b); } -void SMESH_Actor::SetPreHighlightColor(float r,float g,float b){ +void SMESH_ActorDef::SetPreHighlightColor(float r,float g,float b){ myPreselectProp->SetColor(r,g,b); Modified(); } -void SMESH_Actor::GetPreHighlightColor(float& r,float& g,float& b){ +void SMESH_ActorDef::GetPreHighlightColor(float& r,float& g,float& b){ ::GetColor(myPreselectProp,r,g,b); } -float SMESH_Actor::GetLineWidth(){ +float SMESH_ActorDef::GetLineWidth(){ return myEdgeProp->GetLineWidth(); } -void SMESH_Actor::SetLineWidth(float theVal){ +void SMESH_ActorDef::SetLineWidth(float theVal){ myEdgeProp->SetLineWidth(theVal); my1DProp->SetLineWidth(theVal + aLineWidthInc); @@ -1325,7 +1392,7 @@ void SMESH_Actor::SetLineWidth(float theVal){ } -void SMESH_Actor::SetNodeSize(float theVal){ +void SMESH_ActorDef::SetNodeSize(float theVal){ myNodeProp->SetPointSize(theVal); myHighlightProp->SetPointSize(theVal); myPreselectProp->SetPointSize(theVal); @@ -1336,17 +1403,17 @@ void SMESH_Actor::SetNodeSize(float theVal){ Modified(); } -float SMESH_Actor::GetNodeSize(){ +float SMESH_ActorDef::GetNodeSize(){ return myNodeProp->GetPointSize(); } -int SMESH_Actor::GetObjDimension( const int theObjId ) +int SMESH_ActorDef::GetObjDimension( const int theObjId ) { return myVisualObj->GetElemDimension( theObjId ); } -vtkImplicitBoolean* SMESH_Actor::GetPlaneContainer(){ +vtkImplicitBoolean* SMESH_ActorDef::GetPlaneContainer(){ return myImplicitBoolean; } @@ -1418,17 +1485,16 @@ static void PositionToDistance(vtkDataSet* theDataSet, } -void SMESH_Actor::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane) +void SMESH_ActorDef::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane) { thePlane->SetNormal(theDir); float anOrigin[3]; ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin); thePlane->SetOrigin(anOrigin); - Update(); } -void SMESH_Actor::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane) +void SMESH_ActorDef::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane) { thePlane->GetNormal(theDir); diff --git a/src/OBJECT/SMESH_Actor.h b/src/OBJECT/SMESH_Actor.h index b2f68c394..ad041c275 100644 --- a/src/OBJECT/SMESH_Actor.h +++ b/src/OBJECT/SMESH_Actor.h @@ -32,33 +32,16 @@ #include "SALOME_Actor.h" #include "SMESH_Object.h" -class vtkProperty; -class vtkShrinkFilter; -class vtkPolyDataMapper; class vtkUnstructuredGrid; -class vtkMergeFilter; -class vtkPolyData; - -class vtkMapper; -class vtkActor2D; -class vtkMaskPoints; -class vtkCellCenters; -class vtkLabeledDataMapper; -class vtkSelectVisiblePoints; class vtkScalarBarActor; -class vtkLookupTable; class vtkPlane; class vtkImplicitBoolean; -class vtkTimeStamp; - -class SMESH_DeviceActor; - - -class SMESH_Actor : public SALOME_Actor{ - friend class SMESH_VisualObj; +class SMESH_Actor: public SALOME_Actor +{ + static SMESH_Actor* New() { return NULL;} public: vtkTypeMacro(SMESH_Actor,SALOME_Actor); @@ -67,182 +50,66 @@ class SMESH_Actor : public SALOME_Actor{ const char* theName, int theIsClear); - virtual void ReleaseGraphicsResources(vtkWindow *renWin); - virtual int RenderOpaqueGeometry(vtkViewport *viewport); - virtual int RenderTranslucentGeometry(vtkViewport *viewport); - virtual void Render(vtkRenderer *ren); - - virtual void AddToRender(vtkRenderer* theRenderer); - virtual void RemoveFromRender(vtkRenderer* theRenderer); - - virtual bool hasHighlight() { return true; } - virtual void highlight(bool theHighlight); - virtual void SetPreSelected(bool thePreselect = false); - - virtual bool IsInfinitive(); - - virtual void SetOpacity(float theValue); - virtual float GetOpacity(); - - void SetSufaceColor(float r,float g,float b); - void GetSufaceColor(float& r,float& g,float& b); - - void SetBackSufaceColor(float r,float g,float b); - void GetBackSufaceColor(float& r,float& g,float& b); - - void SetEdgeColor(float r,float g,float b); - void GetEdgeColor(float& r,float& g,float& b); + virtual void SetSufaceColor(float r,float g,float b) = 0; + virtual void GetSufaceColor(float& r,float& g,float& b) = 0; + + virtual void SetBackSufaceColor(float r,float g,float b) = 0; + virtual void GetBackSufaceColor(float& r,float& g,float& b) = 0; + + virtual void SetEdgeColor(float r,float g,float b) = 0; + virtual void GetEdgeColor(float& r,float& g,float& b) = 0; - void SetNodeColor(float r,float g,float b); - void GetNodeColor(float& r,float& g,float& b); + virtual void SetNodeColor(float r,float g,float b) = 0; + virtual void GetNodeColor(float& r,float& g,float& b) = 0; - void SetHighlightColor(float r,float g,float b); - void GetHighlightColor(float& r,float& g,float& b); + virtual void SetHighlightColor(float r,float g,float b) = 0; + virtual void GetHighlightColor(float& r,float& g,float& b) = 0; - void SetPreHighlightColor(float r,float g,float b); - void GetPreHighlightColor(float& r,float& g,float& b); + virtual void SetPreHighlightColor(float r,float g,float b) = 0; + virtual void GetPreHighlightColor(float& r,float& g,float& b) = 0; - float GetLineWidth(); - void SetLineWidth(float theVal); - - void SetNodeSize(float size) ; - float GetNodeSize() ; - - virtual int GetNodeObjId(int theVtkID); - virtual float* GetNodeCoord(int theObjID); + virtual float GetLineWidth() = 0; + virtual void SetLineWidth(float theVal) = 0; - virtual int GetElemObjId(int theVtkID); - virtual vtkCell* GetElemCell(int theObjID); - - virtual int GetObjDimension( const int theObjId ); - - virtual void SetVisibility(int theMode); - void SetVisibility(int theMode, bool theIsUpdateRepersentation); + virtual void SetNodeSize(float size) = 0; + virtual float GetNodeSize() = 0; enum EReperesent { ePoint, eEdge, eSurface}; - virtual void SetRepresentation(int theMode); - void SetPointRepresentation(bool theIsPointsVisible); - bool GetPointRepresentation(); - - virtual float* GetBounds(); - virtual void SetTransform(SALOME_Transform* theTransform); - - vtkUnstructuredGrid* GetUnstructuredGrid(); - virtual vtkDataSet* GetInput(); - virtual vtkMapper* GetMapper(); - - virtual float GetShrinkFactor(); - virtual void SetShrinkFactor(float value ); - - virtual bool IsShrunkable() { return myIsShrinkable;} - virtual bool IsShrunk() { return myIsShrunk;} - virtual void SetShrink(); - virtual void UnShrink(); - - void SetPointsLabeled(bool theIsPointsLabeled); - bool GetPointsLabeled(){ return myIsPointsLabeled;} - - void SetCellsLabeled(bool theIsCellsLabeled); - bool GetCellsLabeled(){ return myIsCellsLabeled;} - - enum eControl{eNone, eLengthEdges, eFreeBorders, eFreeEdges, eMultiConnection, - eArea, eTaper, eAspectRatio, eMinimumAngle, eWarping, eSkew}; - void SetControlMode(eControl theMode); - eControl GetControlMode(){ return myColorMode;} - - enum e1DControl{e1DNone, e1DColored, e1DHighlited}; - e1DControl Get1DControlMode(){ return my1DColorMode;} - - vtkScalarBarActor* GetScalarBarActor(){ return myScalarBarActor;} - - void SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane); - void GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane); - - vtkImplicitBoolean* GetPlaneContainer(); + + enum EEntityMode { eEdges = 0x01, eFaces = 0x02, eVolumes = 0x04, eAllEntity = 0x07}; + virtual void SetEntityMode(unsigned int theMode) = 0; + virtual unsigned int GetEntityMode() const = 0; - TVisualObjPtr GetObject() { return myVisualObj;} + virtual void SetPointRepresentation(bool theIsPointsVisible) = 0; + virtual bool GetPointRepresentation() = 0; - void SetControlsPrecision( const long p ) { myControlsPrecision = p; } - long GetControlsPrecision() const { return myControlsPrecision; } + virtual vtkUnstructuredGrid* GetUnstructuredGrid() = 0; - protected: - TVisualObjPtr myVisualObj; - vtkTimeStamp* myTimeStamp; + virtual void SetShrinkFactor(float theValue) = 0; - vtkScalarBarActor* myScalarBarActor; - vtkLookupTable* myLookupTable; + virtual void SetPointsLabeled(bool theIsPointsLabeled) = 0; + virtual bool GetPointsLabeled() = 0; - vtkProperty* mySurfaceProp; - vtkProperty* myBackSurfaceProp; - vtkProperty* myEdgeProp; - vtkProperty* myNodeProp; + virtual void SetCellsLabeled(bool theIsCellsLabeled) = 0; + virtual bool GetCellsLabeled() = 0; - SMESH_DeviceActor* myBaseActor; - SMESH_DeviceActor* myNodeActor; - SMESH_DeviceActor* myPickableActor; + enum eControl{eNone, eLength, eLength2D, eFreeBorders, eFreeEdges, eMultiConnection, + eArea, eTaper, eAspectRatio, eMinimumAngle, eWarping, eSkew, + eAspectRatio3D, eMultiConnection2D}; + virtual void SetControlMode(eControl theMode) = 0; + virtual eControl GetControlMode() = 0; - vtkProperty* myHighlightProp; - vtkProperty* myPreselectProp; - SMESH_DeviceActor* myHighlitableActor; - SMESH_DeviceActor* myNodeHighlitableActor; + virtual vtkScalarBarActor* GetScalarBarActor() = 0; - eControl myColorMode; - SMESH_DeviceActor* my2DActor; - SMESH_DeviceActor* my3DActor; - SMESH_DeviceActor* myControlActor; + virtual void SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane) = 0; + virtual void GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane) = 0; - e1DControl my1DColorMode; - vtkProperty* my1DProp; - SMESH_DeviceActor* my1DActor; - vtkProperty* my1DExtProp; - SMESH_DeviceActor* my1DExtActor; + virtual vtkImplicitBoolean* GetPlaneContainer() = 0; - bool myIsPointsVisible; + virtual TVisualObjPtr GetObject() = 0; - bool myIsShrinkable; - bool myIsShrunk; - - bool myIsPointsLabeled; - vtkUnstructuredGrid* myPointsNumDataSet; - vtkActor2D *myPointLabels; - vtkMaskPoints* myPtsMaskPoints; - vtkLabeledDataMapper* myPtsLabeledDataMapper; - vtkSelectVisiblePoints* myPtsSelectVisiblePoints; - - bool myIsCellsLabeled; - vtkUnstructuredGrid* myCellsNumDataSet; - vtkActor2D *myCellsLabels; - vtkMaskPoints* myClsMaskPoints; - vtkCellCenters* myCellCenters; - vtkLabeledDataMapper* myClsLabeledDataMapper; - vtkSelectVisiblePoints* myClsSelectVisiblePoints; - - vtkImplicitBoolean* myImplicitBoolean; - - long myControlsPrecision; - - SMESH_Actor(); - ~SMESH_Actor(); - - bool Init(TVisualObjPtr theVisualObj, - const char* theEntry, - const char* theName, - int theIsClear); - - void SetIsShrunkable(bool theShrunkable); - void UpdateHighlight(); - void Update(); - - private: - // hide the two parameter Render() method from the user and the compiler. - virtual void Render(vtkRenderer *, vtkMapper *) {}; - virtual void ShallowCopy(vtkProp *prop); - virtual void SetMapper(vtkMapper *); - static SMESH_Actor* New(); - - // Not implemented. - SMESH_Actor(const SMESH_Actor&); - void operator=(const SMESH_Actor&); + virtual void SetControlsPrecision( const long ) = 0; + virtual long GetControlsPrecision() const = 0; }; diff --git a/src/OBJECT/SMESH_ActorDef.h b/src/OBJECT/SMESH_ActorDef.h new file mode 100644 index 000000000..943fc5ee5 --- /dev/null +++ b/src/OBJECT/SMESH_ActorDef.h @@ -0,0 +1,244 @@ +// SMESH OBJECT : interactive object for SMESH visualization +// +// 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 : SMESH_ActorDef.h +// Author : Nicolas REJNERI +// Module : SMESH +// $Header$ + +#ifndef SMESH_ACTORDEF_H +#define SMESH_ACTORDEF_H + +#include "SMESH_Actor.h" +#include "SMESH_Object.h" + +class vtkProperty; +class vtkShrinkFilter; +class vtkPolyDataMapper; +class vtkUnstructuredGrid; +class vtkMergeFilter; +class vtkPolyData; + +class vtkMapper; +class vtkActor2D; +class vtkMaskPoints; +class vtkCellCenters; +class vtkLabeledDataMapper; +class vtkSelectVisiblePoints; + +class vtkScalarBarActor; +class vtkLookupTable; + +class vtkPlane; +class vtkImplicitBoolean; + +class vtkTimeStamp; + +class SMESH_DeviceActor; + + +class SMESH_ActorDef : public SMESH_Actor{ + friend class SMESH_VisualObj; + friend class SMESH_Actor; + + public: + vtkTypeMacro(SMESH_ActorDef,SMESH_Actor); + + virtual void ReleaseGraphicsResources(vtkWindow *renWin); + virtual int RenderOpaqueGeometry(vtkViewport *viewport); + virtual int RenderTranslucentGeometry(vtkViewport *viewport); + virtual void Render(vtkRenderer *ren); + + virtual void AddToRender(vtkRenderer* theRenderer); + virtual void RemoveFromRender(vtkRenderer* theRenderer); + + virtual bool hasHighlight() { return true; } + virtual void highlight(bool theHighlight); + virtual void SetPreSelected(bool thePreselect = false); + + virtual bool IsInfinitive(); + + virtual void SetOpacity(float theValue); + virtual float GetOpacity(); + + virtual void SetSufaceColor(float r,float g,float b); + virtual void GetSufaceColor(float& r,float& g,float& b); + + virtual void SetBackSufaceColor(float r,float g,float b); + virtual void GetBackSufaceColor(float& r,float& g,float& b); + + virtual void SetEdgeColor(float r,float g,float b); + virtual void GetEdgeColor(float& r,float& g,float& b); + + virtual void SetNodeColor(float r,float g,float b); + virtual void GetNodeColor(float& r,float& g,float& b); + + virtual void SetHighlightColor(float r,float g,float b); + virtual void GetHighlightColor(float& r,float& g,float& b); + + virtual void SetPreHighlightColor(float r,float g,float b); + virtual void GetPreHighlightColor(float& r,float& g,float& b); + + virtual float GetLineWidth(); + virtual void SetLineWidth(float theVal); + + virtual void SetNodeSize(float size) ; + virtual float GetNodeSize() ; + + virtual int GetNodeObjId(int theVtkID); + virtual float* GetNodeCoord(int theObjID); + + virtual int GetElemObjId(int theVtkID); + virtual vtkCell* GetElemCell(int theObjID); + + virtual int GetObjDimension( const int theObjId ); + + virtual void SetVisibility(int theMode); + void SetVisibility(int theMode, bool theIsUpdateRepersentation); + + virtual void SetRepresentation(int theMode); + + virtual unsigned int GetEntityMode() const { return myEntityMode;} + virtual void SetEntityMode(unsigned int theMode); + + virtual void SetPointRepresentation(bool theIsPointsVisible); + virtual bool GetPointRepresentation(); + + virtual float* GetBounds(); + virtual void SetTransform(SALOME_Transform* theTransform); + + virtual vtkUnstructuredGrid* GetUnstructuredGrid(); + virtual vtkDataSet* GetInput(); + virtual vtkMapper* GetMapper(); + + virtual float GetShrinkFactor(); + virtual void SetShrinkFactor(float theValue); + + virtual bool IsShrunkable() { return myIsShrinkable;} + virtual bool IsShrunk() { return myIsShrunk;} + virtual void SetShrink(); + virtual void UnShrink(); + + virtual void SetPointsLabeled(bool theIsPointsLabeled); + virtual bool GetPointsLabeled(){ return myIsPointsLabeled;} + + virtual void SetCellsLabeled(bool theIsCellsLabeled); + virtual bool GetCellsLabeled(){ return myIsCellsLabeled;} + + virtual void SetControlMode(eControl theMode); + virtual eControl GetControlMode(){ return myControlMode;} + + virtual vtkScalarBarActor* GetScalarBarActor(){ return myScalarBarActor;} + + virtual void SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane); + virtual void GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane); + + virtual vtkImplicitBoolean* GetPlaneContainer(); + + virtual TVisualObjPtr GetObject() { return myVisualObj;} + + virtual void SetControlsPrecision( const long p ) { myControlsPrecision = p; } + virtual long GetControlsPrecision() const { return myControlsPrecision; } + + protected: + TVisualObjPtr myVisualObj; + vtkTimeStamp* myTimeStamp; + + vtkScalarBarActor* myScalarBarActor; + vtkLookupTable* myLookupTable; + + vtkProperty* mySurfaceProp; + vtkProperty* myBackSurfaceProp; + vtkProperty* myEdgeProp; + vtkProperty* myNodeProp; + + SMESH_DeviceActor* myBaseActor; + SMESH_DeviceActor* myNodeActor; + SMESH_DeviceActor* myPickableActor; + + vtkProperty* myHighlightProp; + vtkProperty* myPreselectProp; + SMESH_DeviceActor* myHighlitableActor; + SMESH_DeviceActor* myNodeHighlitableActor; + + eControl myControlMode; + SMESH_DeviceActor* my2DActor; + SMESH_DeviceActor* my3DActor; + SMESH_DeviceActor* myControlActor; + + vtkProperty* my1DProp; + SMESH_DeviceActor* my1DActor; + vtkProperty* my1DExtProp; + SMESH_DeviceActor* my1DExtActor; + + unsigned int myEntityMode; + bool myIsPointsVisible; + + bool myIsShrinkable; + bool myIsShrunk; + + bool myIsPointsLabeled; + vtkUnstructuredGrid* myPointsNumDataSet; + vtkActor2D *myPointLabels; + vtkMaskPoints* myPtsMaskPoints; + vtkLabeledDataMapper* myPtsLabeledDataMapper; + vtkSelectVisiblePoints* myPtsSelectVisiblePoints; + + bool myIsCellsLabeled; + vtkUnstructuredGrid* myCellsNumDataSet; + vtkActor2D *myCellsLabels; + vtkMaskPoints* myClsMaskPoints; + vtkCellCenters* myCellCenters; + vtkLabeledDataMapper* myClsLabeledDataMapper; + vtkSelectVisiblePoints* myClsSelectVisiblePoints; + + vtkImplicitBoolean* myImplicitBoolean; + + long myControlsPrecision; + + SMESH_ActorDef(); + ~SMESH_ActorDef(); + + bool Init(TVisualObjPtr theVisualObj, + const char* theEntry, + const char* theName, + int theIsClear); + + void SetIsShrunkable(bool theShrunkable); + void UpdateHighlight(); + void Update(); + + private: + // hide the two parameter Render() method from the user and the compiler. + virtual void Render(vtkRenderer *, vtkMapper *) {}; + virtual void ShallowCopy(vtkProp *prop); + virtual void SetMapper(vtkMapper *); + static SMESH_ActorDef* New(); + + // Not implemented. + SMESH_ActorDef(const SMESH_ActorDef&); + void operator=(const SMESH_ActorDef&); +}; + + +#endif //SMESH_ACTORDEF_H diff --git a/src/OBJECT/SMESH_ActorUtils.cxx b/src/OBJECT/SMESH_ActorUtils.cxx index a5823c66f..fdaa86c25 100644 --- a/src/OBJECT/SMESH_ActorUtils.cxx +++ b/src/OBJECT/SMESH_ActorUtils.cxx @@ -23,6 +23,9 @@ #include "QAD_Config.h" #include "utilities.h" +#include +#include + #ifdef _DEBUG_ static int MYDEBUG = 1; #else @@ -30,10 +33,22 @@ static int MYDEBUG = 0; #endif namespace SMESH{ + float GetFloat(const QString& theValue, float theDefault){ if(theValue.isEmpty()) return theDefault; QString aValue = QAD_CONFIG->getSetting(theValue); if(aValue.isEmpty()) return theDefault; return aValue.toFloat(); } + + void WriteUnstructuredGrid(vtkUnstructuredGrid* theGrid, const char* theFileName){ + vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New(); + aWriter->SetFileName(theFileName); + aWriter->SetInput(theGrid); + if(theGrid->GetNumberOfCells()){ + aWriter->Write(); + } + aWriter->Delete(); + } + } diff --git a/src/OBJECT/SMESH_ActorUtils.h b/src/OBJECT/SMESH_ActorUtils.h index 459549524..b9a01e003 100644 --- a/src/OBJECT/SMESH_ActorUtils.h +++ b/src/OBJECT/SMESH_ActorUtils.h @@ -22,10 +22,14 @@ #include +class vtkUnstructuredGrid; namespace SMESH{ + float GetFloat(const QString& theValue, float theDefault = 0); -} + void WriteUnstructuredGrid(vtkUnstructuredGrid* theGrid, const char* theFileName); + +} #endif diff --git a/src/OBJECT/SMESH_DeviceActor.cxx b/src/OBJECT/SMESH_DeviceActor.cxx index 79d20d813..16ead487f 100644 --- a/src/OBJECT/SMESH_DeviceActor.cxx +++ b/src/OBJECT/SMESH_DeviceActor.cxx @@ -24,19 +24,19 @@ // File : SMESH_Actor.cxx // Author : Nicolas REJNERI // Module : SMESH -// $Header$ +// $Header$Header$ #include "SMESH_DeviceActor.h" #include "SMESH_ExtractGeometry.h" +#include "SMESH_ControlsDef.hxx" +#include "SMESH_ActorUtils.h" #include "SALOME_Transform.h" #include "SALOME_TransformFilter.h" #include "SALOME_PassThroughFilter.h" #include "SALOME_ExtractUnstructuredGrid.h" -#include "utilities.h" - // VTK Includes #include #include @@ -61,12 +61,12 @@ #include +#include "utilities.h" + #ifdef _DEBUG_ static int MYDEBUG = 0; -static int MYDEBUGWITHFILES = 0; #else static int MYDEBUG = 0; -static int MYDEBUGWITHFILES = 0; #endif using namespace std; @@ -166,7 +166,7 @@ void SMESH_DeviceActor::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid){ myExtractUnstructuredGrid->SetInput(myExtractGeometry->GetOutput()); myMergeFilter->SetGeometry(myExtractUnstructuredGrid->GetOutput()); - + theGrid = static_cast(myMergeFilter->GetOutput()); int anId = 0; @@ -261,6 +261,146 @@ void SMESH_DeviceActor::SetControlMode(SMESH::Controls::FunctorPtr theFunctor, theScalarBarActor->SetVisibility(anIsInitialized); } +void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor, + SMESH_DeviceActor* theDeviceActor, + vtkScalarBarActor* theScalarBarActor, + vtkLookupTable* theLookupTable) +{ + bool anIsInitialized = theFunctor; + + using namespace SMESH::Controls; + if (anIsInitialized){ + if (Length2D* aLength2D = dynamic_cast(theFunctor.get())){ + SMESH::Controls::Length2D::TValues aValues; + + myVisualObj->UpdateFunctor(theFunctor); + + aLength2D->GetValues(aValues); + vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New(); + vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid(); + + aDataSet->SetPoints(aGrid->GetPoints()); + + vtkIdType aNbCells = aValues.size(); + + vtkDoubleArray *aScalars = vtkDoubleArray::New(); + aScalars->SetNumberOfComponents(1); + aScalars->SetNumberOfTuples(aNbCells); + + vtkIdType aCellsSize = 3*aNbCells; + vtkCellArray* aConnectivity = vtkCellArray::New(); + aConnectivity->Allocate( aCellsSize, 0 ); + + vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); + aCellTypesArray->SetNumberOfComponents( 1 ); + aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() ); + + vtkIdList *anIdList = vtkIdList::New(); + anIdList->SetNumberOfIds(2); + + Length2D::TValues::const_iterator anIter = aValues.begin(); + for(vtkIdType aVtkId = 0; anIter != aValues.end(); anIter++,aVtkId++){ + const Length2D::Value& aValue = *anIter; + int aNode[2] = { + myVisualObj->GetNodeVTKId(aValue.myPntId[0]), + myVisualObj->GetNodeVTKId(aValue.myPntId[1]) + }; + if(aNode[0] >= 0 && aNode[1] >= 0){ + anIdList->SetId( 0, aNode[0] ); + anIdList->SetId( 1, aNode[1] ); + aConnectivity->InsertNextCell( anIdList ); + aCellTypesArray->InsertNextValue( VTK_LINE ); + aScalars->SetValue(aVtkId,aValue.myLength); + } + } + + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); + aCellLocationsArray->SetNumberOfComponents( 1 ); + aCellLocationsArray->SetNumberOfTuples( aNbCells ); + + aConnectivity->InitTraversal(); + for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) + aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); + + aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); + SetUnstructuredGrid(aDataSet); + + aDataSet->GetCellData()->SetScalars(aScalars); + aScalars->Delete(); + + theLookupTable->SetRange(aScalars->GetRange()); + theLookupTable->Build(); + + myMergeFilter->SetScalars(aDataSet); + aDataSet->Delete(); + } + else if (MultiConnection2D* aMultiConnection2D = dynamic_cast(theFunctor.get())){ + SMESH::Controls::MultiConnection2D::MValues aValues; + + myVisualObj->UpdateFunctor(theFunctor); + + aMultiConnection2D->GetValues(aValues); + vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New(); + vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid(); + aDataSet->SetPoints(aGrid->GetPoints()); + + vtkIdType aNbCells = aValues.size(); + vtkDoubleArray *aScalars = vtkDoubleArray::New(); + aScalars->SetNumberOfComponents(1); + aScalars->SetNumberOfTuples(aNbCells); + + vtkIdType aCellsSize = 3*aNbCells; + vtkCellArray* aConnectivity = vtkCellArray::New(); + aConnectivity->Allocate( aCellsSize, 0 ); + + vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); + aCellTypesArray->SetNumberOfComponents( 1 ); + aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() ); + + vtkIdList *anIdList = vtkIdList::New(); + anIdList->SetNumberOfIds(2); + + MultiConnection2D::MValues::const_iterator anIter = aValues.begin(); + int i = 0; + for(vtkIdType aVtkId; anIter != aValues.end(); anIter++,i++){ + const MultiConnection2D::Value& aValue = (*anIter).first; + int aNode[2] = { + myVisualObj->GetNodeVTKId(aValue.myPntId[0]), + myVisualObj->GetNodeVTKId(aValue.myPntId[1]) + }; + if(aNode[0] >= 0 && aNode[1] >= 0){ + anIdList->SetId( 0, aNode[0] ); + anIdList->SetId( 1, aNode[1] ); + aConnectivity->InsertNextCell( anIdList ); + aCellTypesArray->InsertNextValue( VTK_LINE ); + aScalars->SetValue(i,(*anIter).second); + } + } + + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); + aCellLocationsArray->SetNumberOfComponents( 1 ); + aCellLocationsArray->SetNumberOfTuples( aNbCells ); + + aConnectivity->InitTraversal(); + for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) + aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); + + aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); + SetUnstructuredGrid(aDataSet); + + aDataSet->GetCellData()->SetScalars(aScalars); + aScalars->Delete(); + + theLookupTable->SetRange(aScalars->GetRange()); + theLookupTable->Build(); + + myMergeFilter->SetScalars(aDataSet); + aDataSet->Delete(); + } + } + GetMapper()->SetScalarVisibility(anIsInitialized); + theScalarBarActor->SetVisibility(anIsInitialized); +} void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor, SMESH_DeviceActor* theDeviceActor) @@ -304,7 +444,7 @@ void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor anIdList->SetNumberOfIds(2); FreeEdges::TBorders::const_iterator anIter = aBorders.begin(); - for(vtkIdType aVtkId; anIter != aBorders.end(); anIter++){ + for(; anIter != aBorders.end(); anIter++){ const FreeEdges::Border& aBorder = *anIter; int aNode[2] = { myVisualObj->GetNodeVTKId(aBorder.myPntId[0]), @@ -331,10 +471,12 @@ void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor SetUnstructuredGrid(aDataSet); aDataSet->Delete(); - } + } } + + unsigned long int SMESH_DeviceActor::GetMTime(){ unsigned long mTime = this->Superclass::GetMTime(); mTime = max(mTime,myExtractGeometry->GetMTime()); diff --git a/src/OBJECT/SMESH_DeviceActor.h b/src/OBJECT/SMESH_DeviceActor.h index 5de228b0b..90cd78943 100644 --- a/src/OBJECT/SMESH_DeviceActor.h +++ b/src/OBJECT/SMESH_DeviceActor.h @@ -55,7 +55,7 @@ class SMESH_ExtractGeometry; class SMESH_DeviceActor: public vtkLODActor{ - friend class SMESH_Actor; + friend class SMESH_ActorDef; public: vtkTypeMacro(SMESH_DeviceActor,vtkLODActor); @@ -94,6 +94,10 @@ class SMESH_DeviceActor: public vtkLODActor{ void SetControlMode(SMESH::Controls::FunctorPtr theFunctor, vtkScalarBarActor* theScalarBarActor, vtkLookupTable* theLookupTable); + void SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor, + SMESH_DeviceActor* theDeviceActor, + vtkScalarBarActor* theScalarBarActor, + vtkLookupTable* theLookupTable); void SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor, SMESH_DeviceActor* theDeviceActor); diff --git a/src/OBJECT/SMESH_Object.cxx b/src/OBJECT/SMESH_Object.cxx index 6621177cc..4b43e56ac 100644 --- a/src/OBJECT/SMESH_Object.cxx +++ b/src/OBJECT/SMESH_Object.cxx @@ -25,10 +25,13 @@ // Author : Nicolas REJNERI // Module : SMESH -#include "SMESH_Object.h" +#include "SMESH_ObjectDef.h" +#include "SMESH_ActorUtils.h" + #include "SMDS_Mesh.hxx" -#include "SALOME_ExtractUnstructuredGrid.h" #include "SMESH_Actor.h" +#include "SMESH_ControlsDef.hxx" +#include "SALOME_ExtractUnstructuredGrid.h" #include CORBA_SERVER_HEADER(SALOME_Exception) @@ -39,8 +42,6 @@ #include #include -#include -#include #include #include @@ -68,17 +69,6 @@ static int MYDEBUGWITHFILES = 0; #endif -void WriteUnstructuredGrid(vtkUnstructuredGrid* theGrid, const char* theFileName){ - vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New(); - aWriter->SetFileName(theFileName); - aWriter->SetInput(theGrid); - if(theGrid->GetNumberOfCells()){ - aWriter->Write(); - } - aWriter->Delete(); -} - - namespace{ inline const SMDS_MeshNode* FindNode(const SMDS_Mesh* theMesh, int theId){ @@ -117,7 +107,6 @@ namespace{ SMESH::log_array_var& theSeq, CORBA::Long theId) { - const SMESH::double_array& aCoords = theSeq[theId].coords; const SMESH::long_array& anIndexes = theSeq[theId].indexes; CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number; if(3*aNbElems != anIndexes.length()) @@ -136,7 +125,6 @@ namespace{ SMESH::log_array_var& theSeq, CORBA::Long theId) { - const SMESH::double_array& aCoords = theSeq[theId].coords; const SMESH::long_array& anIndexes = theSeq[theId].indexes; CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number; if(4*aNbElems != anIndexes.length()) @@ -156,7 +144,6 @@ namespace{ SMESH::log_array_var theSeq, CORBA::Long theId) { - const SMESH::double_array& aCoords = theSeq[theId].coords; const SMESH::long_array& anIndexes = theSeq[theId].indexes; CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number; if(5*aNbElems != anIndexes.length()) @@ -177,7 +164,6 @@ namespace{ SMESH::log_array_var& theSeq, CORBA::Long theId) { - const SMESH::double_array& aCoords = theSeq[theId].coords; const SMESH::long_array& anIndexes = theSeq[theId].indexes; CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number; if(5*aNbElems != anIndexes.length()) @@ -198,7 +184,6 @@ namespace{ SMESH::log_array_var& theSeq, CORBA::Long theId) { - const SMESH::double_array& aCoords = theSeq[theId].coords; const SMESH::long_array& anIndexes = theSeq[theId].indexes; CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number; if(6*aNbElems != anIndexes.length()) @@ -220,7 +205,6 @@ namespace{ SMESH::log_array_var& theSeq, CORBA::Long theId) { - const SMESH::double_array& aCoords = theSeq[theId].coords; const SMESH::long_array& anIndexes = theSeq[theId].indexes; CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number; if(7*aNbElems != anIndexes.length()) @@ -243,7 +227,6 @@ namespace{ SMESH::log_array_var& theSeq, CORBA::Long theId) { - const SMESH::double_array& aCoords = theSeq[theId].coords; const SMESH::long_array& anIndexes = theSeq[theId].indexes; CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number; if(9*aNbElems != anIndexes.length()) @@ -266,7 +249,7 @@ namespace{ } /* - Class : SMESH_VisualObj + Class : SMESH_VisualObjDef Description : Base class for all mesh objects to be visuilised */ @@ -274,36 +257,39 @@ namespace{ // function : getCellType // purpose : Get type of VTK cell //================================================================================= -static inline vtkIdType getCellType( const SMESH::ElementType theType, +static inline vtkIdType getCellType( const SMDSAbs_ElementType theType, const int theNbNodes ) { switch( theType ) { - case SMESH::EDGE: return theNbNodes == 2 ? VTK_LINE : VTK_EMPTY_CELL; - - case SMESH::FACE : if ( theNbNodes == 3 ) return VTK_TRIANGLE; - else if ( theNbNodes == 4 ) return VTK_QUAD; - else return VTK_EMPTY_CELL; + case SMDSAbs_Edge: + return theNbNodes == 2 ? VTK_LINE : VTK_EMPTY_CELL; - case SMESH::VOLUME: if ( theNbNodes == 4 ) return VTK_TETRA; - else if ( theNbNodes == 5 ) return VTK_PYRAMID; - else if ( theNbNodes == 6 ) return VTK_WEDGE; - else if ( theNbNodes == 8 ) return VTK_HEXAHEDRON; - else return VTK_EMPTY_CELL; + case SMDSAbs_Face : + if ( theNbNodes == 3 ) return VTK_TRIANGLE; + else if ( theNbNodes == 4 ) return VTK_QUAD; + else return VTK_EMPTY_CELL; + + case SMDSAbs_Volume: + if ( theNbNodes == 4 ) return VTK_TETRA; + else if ( theNbNodes == 5 ) return VTK_PYRAMID; + else if ( theNbNodes == 6 ) return VTK_WEDGE; + else if ( theNbNodes == 8 ) return VTK_HEXAHEDRON; + else return VTK_EMPTY_CELL; default: return VTK_EMPTY_CELL; } } //================================================================================= -// functions : SMESH_VisualObj +// functions : SMESH_VisualObjDef // purpose : Constructor //================================================================================= -SMESH_VisualObj::SMESH_VisualObj() +SMESH_VisualObjDef::SMESH_VisualObjDef() { myGrid = vtkUnstructuredGrid::New(); } -SMESH_VisualObj::~SMESH_VisualObj() +SMESH_VisualObjDef::~SMESH_VisualObjDef() { if ( MYDEBUG ) MESSAGE( "~SMESH_MeshObj - myGrid->GetReferenceCount() = " << myGrid->GetReferenceCount() ); @@ -314,37 +300,37 @@ SMESH_VisualObj::~SMESH_VisualObj() // functions : GetNodeObjId, GetNodeVTKId, GetElemObjId, GetElemVTKId // purpose : Methods for retrieving VTK IDs by SMDS IDs and vice versa //================================================================================= -vtkIdType SMESH_VisualObj::GetNodeObjId( int theVTKID ) +vtkIdType SMESH_VisualObjDef::GetNodeObjId( int theVTKID ) { return myVTK2SMDSNodes.find(theVTKID) == myVTK2SMDSNodes.end() ? -1 : myVTK2SMDSNodes[theVTKID]; } -vtkIdType SMESH_VisualObj::GetNodeVTKId( int theObjID ) +vtkIdType SMESH_VisualObjDef::GetNodeVTKId( int theObjID ) { return mySMDS2VTKNodes.find(theObjID) == mySMDS2VTKNodes.end() ? -1 : mySMDS2VTKNodes[theObjID]; } -vtkIdType SMESH_VisualObj::GetElemObjId( int theVTKID ) +vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID ) { return myVTK2SMDSElems.find(theVTKID) == myVTK2SMDSElems.end() ? -1 : myVTK2SMDSElems[theVTKID]; } -vtkIdType SMESH_VisualObj::GetElemVTKId( int theObjID ) +vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID ) { return mySMDS2VTKElems.find(theObjID) == mySMDS2VTKElems.end() ? -1 : mySMDS2VTKElems[theObjID]; } //================================================================================= -// function : SMESH_VisualObj::createPoints +// function : SMESH_VisualObjDef::createPoints // purpose : Create points from nodes //================================================================================= -void SMESH_VisualObj::createPoints( vtkPoints* thePoints ) +void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints ) { if ( thePoints == 0 ) return; TEntityList aNodes; - vtkIdType nbNodes = GetEntities( SMESH::NODE, aNodes ); + vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes ); thePoints->SetNumberOfPoints( nbNodes ); int nbPoints = 0; @@ -371,7 +357,7 @@ void SMESH_VisualObj::createPoints( vtkPoints* thePoints ) // function : buildPrs // purpose : create VTK cells( fill unstructured grid ) //================================================================================= -void SMESH_VisualObj::buildPrs() +void SMESH_VisualObjDef::buildPrs() { try { @@ -395,18 +381,17 @@ void SMESH_VisualObj::buildPrs() } if( MYDEBUG ) MESSAGE( "Update - myGrid->GetNumberOfCells() = "<GetNumberOfCells() ); - if( MYDEBUGWITHFILES ) WriteUnstructuredGrid( myGrid,"/tmp/buildPrs" ); + if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"/tmp/buildPrs" ); } //================================================================================= // function : buildNodePrs // purpose : create VTK cells for nodes //================================================================================= -void SMESH_VisualObj::buildNodePrs() +void SMESH_VisualObjDef::buildNodePrs() { vtkPoints* aPoints = vtkPoints::New(); createPoints( aPoints ); - int nbPoints = aPoints->GetNumberOfPoints(); myGrid->SetPoints( aPoints ); aPoints->Delete(); @@ -414,6 +399,7 @@ void SMESH_VisualObj::buildNodePrs() // Create cells /* + int nbPoints = aPoints->GetNumberOfPoints(); vtkIdList *anIdList = vtkIdList::New(); anIdList->SetNumberOfIds( 1 ); @@ -452,7 +438,33 @@ void SMESH_VisualObj::buildNodePrs() // function : buildElemPrs // purpose : Create VTK cells for elements //================================================================================= -void SMESH_VisualObj::buildElemPrs() + +namespace{ + typedef std::vector TConnect; + + int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter, + TConnect& theConnect) + { + theConnect.clear(); + for(; theNodesIter->more();) + theConnect.push_back(theNodesIter->next()); + return theConnect.size(); + } + + inline + void SetId(vtkIdList *theIdList, + const SMESH_VisualObjDef::TMapOfIds& theSMDS2VTKNodes, + const TConnect& theConnect, + int thePosition, + int theId) + { + theIdList->SetId(thePosition,theSMDS2VTKNodes.find(theConnect[theId]->GetID())->second); + } + +} + + +void SMESH_VisualObjDef::buildElemPrs() { // Create points @@ -466,16 +478,16 @@ void SMESH_VisualObj::buildElemPrs() // Calculate cells size - static SMESH::ElementType aTypes[ 3 ] = { SMESH::EDGE, SMESH::FACE, SMESH::VOLUME }; + static SMDSAbs_ElementType aTypes[ 3 ] = { SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume }; // get entity data - map< int, int > nbEnts; - map< int, TEntityList > anEnts; + map nbEnts; + map anEnts; for ( int i = 0; i <= 2; i++ ) nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] ); - vtkIdType aCellsSize = 3 * nbEnts[ SMESH::EDGE ]; + vtkIdType aCellsSize = 3 * nbEnts[ SMDSAbs_Edge ]; for ( int i = 1; i <= 2; i++ ) // iterate through faces and volumes { @@ -488,7 +500,7 @@ void SMESH_VisualObj::buildElemPrs() } } - vtkIdType aNbCells = nbEnts[ SMESH::EDGE ] + nbEnts[ SMESH::FACE ] + nbEnts[ SMESH::VOLUME ]; + vtkIdType aNbCells = nbEnts[ SMDSAbs_Edge ] + nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ]; if ( MYDEBUG ) MESSAGE( "Update - aNbCells = "< -#include #include #include #include "SMESH_Controls.hxx" +#include "SMDSAbs_ElementType.hxx" -class vtkUnstructuredGrid; -class vtkPoints; -class SALOME_ExtractUnstructuredGrid; - -class SMESH_Actor; class SMDS_Mesh; -class SMDS_MeshNode; -class SMDS_MeshElement; - -class SMESH_VisualObj; -typedef boost::shared_ptr TVisualObjPtr; - +class vtkUnstructuredGrid; /* Class : SMESH_VisualObj @@ -60,155 +44,27 @@ typedef boost::shared_ptr TVisualObjPtr; */ class SMESH_VisualObj { -protected: - - typedef std::list TEntityList; - typedef std::map TMapOfIds; - -public: - SMESH_VisualObj(); - virtual ~SMESH_VisualObj(); - - virtual void Update( int theIsClear = true ) = 0; - virtual void UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor ) = 0; - virtual int GetElemDimension( const int theObjId ) = 0; - - virtual int GetNbEntities( const SMESH::ElementType) const = 0; - virtual int GetEntities( const SMESH::ElementType, TEntityList& ) const = 0; - virtual bool IsNodePrs() const = 0; - virtual SMDS_Mesh* GetMesh() const = 0; - - bool GetEdgeNodes( const int theElemId, - const int theEdgeNum, - int& theNodeId1, - int& theNodeId2 ) const; - - vtkUnstructuredGrid* GetUnstructuredGrid() { return myGrid; } - - vtkIdType GetNodeObjId( int theVTKID ); - vtkIdType GetNodeVTKId( int theObjID ); - vtkIdType GetElemObjId( int theVTKID ); - vtkIdType GetElemVTKId( int theObjID ); - -protected: - - void createPoints( vtkPoints* ); - void buildPrs(); - void buildNodePrs(); - void buildElemPrs(); - -private: - - TMapOfIds mySMDS2VTKNodes; - TMapOfIds myVTK2SMDSNodes; - TMapOfIds mySMDS2VTKElems; - TMapOfIds myVTK2SMDSElems; - - vtkUnstructuredGrid* myGrid; -}; - - -/* - Class : SMESH_MeshObj - Description : Class for visualisation of mesh -*/ - -class SMESH_MeshObj: public SMESH_VisualObj -{ -public: - - SMESH_MeshObj( SMESH::SMESH_Mesh_ptr ); - virtual ~SMESH_MeshObj(); - - virtual void Update( int theIsClear = true ); - - virtual int GetNbEntities( const SMESH::ElementType) const; - virtual int GetEntities( const SMESH::ElementType, TEntityList& ) const; - virtual bool IsNodePrs() const; - - virtual int GetElemDimension( const int theObjId ); - - virtual void UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor ); - - SMESH::SMESH_Mesh_ptr GetMeshServer() { return myMeshServer.in(); } - SMDS_Mesh* GetMesh() const { return myMesh; } - -protected: - - SMESH::SMESH_Mesh_var myMeshServer; - SMDS_Mesh* myMesh; -}; - - -/* - Class : SMESH_SubMeshObj - Description : Base class for visualisation of submeshes and groups -*/ - -class SMESH_SubMeshObj: public SMESH_VisualObj -{ public: + virtual void Update( int theIsClear = true ) = 0; + virtual void UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor ) = 0; + virtual int GetElemDimension( const int theObjId ) = 0; - SMESH_SubMeshObj(SMESH_MeshObj* theMeshObj); - virtual ~SMESH_SubMeshObj(); + virtual int GetNbEntities( const SMDSAbs_ElementType theType) const = 0; + virtual SMDS_Mesh* GetMesh() const = 0; - virtual void Update( int theIsClear = true ); + virtual bool GetEdgeNodes( const int theElemId, + const int theEdgeNum, + int& theNodeId1, + int& theNodeId2 ) const = 0; - virtual void UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor ); - virtual int GetElemDimension( const int theObjId ); - virtual SMDS_Mesh* GetMesh() const { return myMeshObj->GetMesh(); } + virtual vtkUnstructuredGrid* GetUnstructuredGrid() = 0; -protected: - - SMESH_MeshObj* myMeshObj; + virtual vtkIdType GetNodeObjId( int theVTKID ) = 0; + virtual vtkIdType GetNodeVTKId( int theObjID ) = 0; + virtual vtkIdType GetElemObjId( int theVTKID ) = 0; + virtual vtkIdType GetElemVTKId( int theObjID ) = 0; }; - -/* - Class : SMESH_GroupObj - Description : Class for visualisation of groups -*/ - -class SMESH_GroupObj: public SMESH_SubMeshObj -{ -public: - SMESH_GroupObj( SMESH::SMESH_GroupBase_ptr, SMESH_MeshObj* ); - virtual ~SMESH_GroupObj(); - - virtual int GetNbEntities( const SMESH::ElementType) const; - virtual int GetEntities( const SMESH::ElementType, TEntityList& ) const; - virtual bool IsNodePrs() const; - -private: - - SMESH::SMESH_GroupBase_var myGroupServer; -}; - - -/* - Class : SMESH_subMeshObj - Description : Class for visualisation of submeshes -*/ - -class SMESH_subMeshObj : public SMESH_SubMeshObj -{ -public: - - SMESH_subMeshObj( SMESH::SMESH_subMesh_ptr, - SMESH_MeshObj* ); - virtual ~SMESH_subMeshObj(); - - virtual int GetNbEntities( const SMESH::ElementType) const; - virtual int GetEntities( const SMESH::ElementType, TEntityList& ) const; - virtual bool IsNodePrs() const; - -protected: - - SMESH::SMESH_subMesh_var mySubMeshServer; -}; - - -extern void WriteUnstructuredGrid(vtkUnstructuredGrid* theGrid, const char* theFileName); - +typedef boost::shared_ptr TVisualObjPtr; #endif diff --git a/src/OBJECT/SMESH_ObjectDef.h b/src/OBJECT/SMESH_ObjectDef.h new file mode 100644 index 000000000..14df168d7 --- /dev/null +++ b/src/OBJECT/SMESH_ObjectDef.h @@ -0,0 +1,202 @@ +// SMESH OBJECT : interactive object for SMESH visualization +// +// 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 : SMESH_Object.h +// Author : Nicolas REJNERI +// Module : SMESH +// $Header$ + +#ifndef SMESH_OBJECTDEF_H +#define SMESH_OBJECTDEF_H + +// IDL Headers +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SMESH_Mesh) +#include CORBA_SERVER_HEADER(SMESH_Group) + +#include +#include + +#include "SMESH_Controls.hxx" +#include "SMESH_Object.h" + +class vtkPoints; +class SALOME_ExtractUnstructuredGrid; + +class SMESH_Actor; +class SMDS_MeshNode; +class SMDS_MeshElement; + +/* + Class : SMESH_VisualObj + Description : Base class for all mesh objects to be visuilised +*/ +class SMESH_VisualObjDef: public SMESH_VisualObj +{ +public: + typedef std::list TEntityList; + typedef std::map TMapOfIds; + + SMESH_VisualObjDef(); + virtual ~SMESH_VisualObjDef(); + + virtual void Update( int theIsClear = true ) = 0; + virtual void UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor ) = 0; + virtual int GetElemDimension( const int theObjId ) = 0; + + virtual int GetNbEntities( const SMDSAbs_ElementType theType) const = 0; + virtual int GetEntities( const SMDSAbs_ElementType, TEntityList& ) const = 0; + virtual bool IsNodePrs() const = 0; + virtual SMDS_Mesh* GetMesh() const = 0; + + virtual bool GetEdgeNodes( const int theElemId, + const int theEdgeNum, + int& theNodeId1, + int& theNodeId2 ) const; + + virtual vtkUnstructuredGrid* GetUnstructuredGrid() { return myGrid; } + + virtual vtkIdType GetNodeObjId( int theVTKID ); + virtual vtkIdType GetNodeVTKId( int theObjID ); + virtual vtkIdType GetElemObjId( int theVTKID ); + virtual vtkIdType GetElemVTKId( int theObjID ); + +protected: + + void createPoints( vtkPoints* ); + void buildPrs(); + void buildNodePrs(); + void buildElemPrs(); + +private: + + TMapOfIds mySMDS2VTKNodes; + TMapOfIds myVTK2SMDSNodes; + TMapOfIds mySMDS2VTKElems; + TMapOfIds myVTK2SMDSElems; + + vtkUnstructuredGrid* myGrid; +}; + + +/* + Class : SMESH_MeshObj + Description : Class for visualisation of mesh +*/ + +class SMESH_MeshObj: public SMESH_VisualObjDef +{ +public: + + SMESH_MeshObj( SMESH::SMESH_Mesh_ptr ); + virtual ~SMESH_MeshObj(); + + virtual void Update( int theIsClear = true ); + + virtual int GetNbEntities( const SMDSAbs_ElementType) const; + virtual int GetEntities( const SMDSAbs_ElementType, TEntityList& ) const; + virtual bool IsNodePrs() const; + + virtual int GetElemDimension( const int theObjId ); + + virtual void UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor ); + + SMESH::SMESH_Mesh_ptr GetMeshServer() { return myMeshServer.in(); } + SMDS_Mesh* GetMesh() const { return myMesh; } + +protected: + + SMESH::SMESH_Mesh_var myMeshServer; + SMDS_Mesh* myMesh; +}; + + +/* + Class : SMESH_SubMeshObj + Description : Base class for visualisation of submeshes and groups +*/ + +class SMESH_SubMeshObj: public SMESH_VisualObjDef +{ +public: + + SMESH_SubMeshObj(SMESH_MeshObj* theMeshObj); + virtual ~SMESH_SubMeshObj(); + + virtual void Update( int theIsClear = true ); + + virtual void UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor ); + virtual int GetElemDimension( const int theObjId ); + virtual SMDS_Mesh* GetMesh() const { return myMeshObj->GetMesh(); } + +protected: + + SMESH_MeshObj* myMeshObj; +}; + + +/* + Class : SMESH_GroupObj + Description : Class for visualisation of groups +*/ + +class SMESH_GroupObj: public SMESH_SubMeshObj +{ +public: + SMESH_GroupObj( SMESH::SMESH_GroupBase_ptr, SMESH_MeshObj* ); + virtual ~SMESH_GroupObj(); + + virtual int GetNbEntities( const SMDSAbs_ElementType) const; + virtual int GetEntities( const SMDSAbs_ElementType, TEntityList& ) const; + virtual bool IsNodePrs() const; + +private: + + SMESH::SMESH_GroupBase_var myGroupServer; +}; + + +/* + Class : SMESH_subMeshObj + Description : Class for visualisation of submeshes +*/ + +class SMESH_subMeshObj : public SMESH_SubMeshObj +{ +public: + + SMESH_subMeshObj( SMESH::SMESH_subMesh_ptr, + SMESH_MeshObj* ); + virtual ~SMESH_subMeshObj(); + + virtual int GetNbEntities( const SMDSAbs_ElementType) const; + virtual int GetEntities( const SMDSAbs_ElementType, TEntityList& ) const; + virtual bool IsNodePrs() const; + +protected: + + SMESH::SMESH_subMesh_var mySubMeshServer; +}; + + +#endif diff --git a/src/SMDS/Makefile.in b/src/SMDS/Makefile.in index 6ce749cf0..d64abd6fe 100644 --- a/src/SMDS/Makefile.in +++ b/src/SMDS/Makefile.in @@ -88,6 +88,7 @@ EXPORT_HEADERS= \ SMDS_TypeOfPosition.hxx \ SMDSAbs_ElementType.hxx \ SMDS_EdgePosition.hxx \ + SMDS_ElemIterator.hxx \ SMDS_FacePosition.hxx \ SMDS_Mesh.hxx \ SMDS_MeshEdge.hxx \ @@ -125,9 +126,9 @@ EXPORT_HEADERS= \ #SMDS_MeshNodeIDFactory.hxx # additionnal information to compil and link file -CPPFLAGS += -I${KERNEL_ROOT_DIR}/include/salome $(BOOST_CPPFLAGS) +CPPFLAGS += -I${KERNEL_ROOT_DIR}/include/salome $(OCC_INCLUDES) $(BOOST_CPPFLAGS) CXXFLAGS += -I${KERNEL_ROOT_DIR}/include/salome -LDFLAGS += -L${KERNEL_ROOT_DIR}/lib/salome +LDFLAGS += -L${KERNEL_ROOT_DIR}/lib/salome $(OCC_KERNEL_LIBS) # additional file to be cleaned diff --git a/src/SMDS/SMDS_ElemIterator.hxx b/src/SMDS/SMDS_ElemIterator.hxx new file mode 100755 index 000000000..c8432afdd --- /dev/null +++ b/src/SMDS/SMDS_ElemIterator.hxx @@ -0,0 +1,40 @@ +// SMESH SMDS : implementaion of Salome mesh data structure +// +// 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 : SMDS_MeshElement.hxx +// Module : SMESH +// Created: 12.01.05 18:02:52 +// Author: Michael Sazonov + +#ifndef SMDS_ElemIterator_HeaderFile +#define SMDS_ElemIterator_HeaderFile + +#include "SMDS_Iterator.hxx" +#include + +class SMDS_MeshElement; + +typedef SMDS_Iterator SMDS_ElemIterator; +typedef boost::shared_ptr > SMDS_ElemIteratorPtr; + +#endif diff --git a/src/SMDS/SMDS_FaceOfEdges.cxx b/src/SMDS/SMDS_FaceOfEdges.cxx index de9092f44..640c55d30 100644 --- a/src/SMDS/SMDS_FaceOfEdges.cxx +++ b/src/SMDS/SMDS_FaceOfEdges.cxx @@ -19,6 +19,10 @@ // // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif + #include "SMDS_FaceOfEdges.hxx" #include "SMDS_IteratorOfElements.hxx" #include "SMDS_MeshNode.hxx" @@ -32,7 +36,7 @@ using namespace std; int SMDS_FaceOfEdges::NbEdges() const { - return myEdges.size(); + return myNbEdges; } int SMDS_FaceOfEdges::NbFaces() const @@ -57,17 +61,23 @@ SMDSAbs_ElementType SMDS_FaceOfEdges::GetType() const return SMDSAbs_Face; } +//======================================================================= +//function : elementsIterator +//purpose : +//======================================================================= + class SMDS_FaceOfEdges_MyIterator:public SMDS_ElemIterator { - const vector& mySet; + const SMDS_MeshEdge* const *mySet; + int myLength; int index; public: - SMDS_FaceOfEdges_MyIterator(const vector& s): - mySet(s),index(0) {} + SMDS_FaceOfEdges_MyIterator(const SMDS_MeshEdge* const *s, int l): + mySet(s),myLength(l),index(0) {} bool more() { - return index myEdges; + const SMDS_MeshEdge* myEdges[4]; + int myNbEdges; }; diff --git a/src/SMDS/SMDS_FaceOfNodes.cxx b/src/SMDS/SMDS_FaceOfNodes.cxx index 2ef48ca8a..aa6870824 100644 --- a/src/SMDS/SMDS_FaceOfNodes.cxx +++ b/src/SMDS/SMDS_FaceOfNodes.cxx @@ -19,6 +19,10 @@ // // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif + #include "SMDS_FaceOfNodes.hxx" #include "SMDS_IteratorOfElements.hxx" #include "SMDS_MeshNode.hxx" @@ -43,8 +47,9 @@ int SMDS_FaceOfNodes::NbFaces() const int SMDS_FaceOfNodes::NbNodes() const { - return myNodes.size(); + return myNbNodes; } + //======================================================================= //function : Print //purpose : @@ -58,41 +63,49 @@ void SMDS_FaceOfNodes::Print(ostream & OS) const OS << myNodes[i] << ") " << endl; } +//======================================================================= +//function : elementsIterator +//purpose : +//======================================================================= + class SMDS_FaceOfNodes_MyIterator:public SMDS_ElemIterator { - const vector& mySet; + const SMDS_MeshNode* const *mySet; + int myLength; int index; public: - SMDS_FaceOfNodes_MyIterator(const vector& s): - mySet(s),index(0) {} + SMDS_FaceOfNodes_MyIterator(const SMDS_MeshNode* const *s, int l): + mySet(s),myLength(l),index(0) {} bool more() { - return index myNodes; + const SMDS_MeshNode* myNodes[4]; + int myNbNodes; }; diff --git a/src/SMDS/SMDS_IteratorOfElements.cxx b/src/SMDS/SMDS_IteratorOfElements.cxx index c18f24d25..472ae0d54 100644 --- a/src/SMDS/SMDS_IteratorOfElements.cxx +++ b/src/SMDS/SMDS_IteratorOfElements.cxx @@ -19,11 +19,15 @@ // // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif + #include "SMDS_IteratorOfElements.hxx" bool SMDS_IteratorOfElements::subMore() { - if((t2Iterator==NULL)||(!t2Iterator->more())) + if((t2Iterator.get()==NULL)||(!t2Iterator->more())) { if(t1Iterator->more()) { @@ -37,7 +41,7 @@ bool SMDS_IteratorOfElements::subMore() const SMDS_MeshElement * SMDS_IteratorOfElements::subNext() { - if((t2Iterator==NULL)||(!t2Iterator->more())) + if((t2Iterator.get()==NULL)||(!t2Iterator->more())) if(t1Iterator->more()) t2Iterator=t1Iterator->next()->elementsIterator(myType); return t2Iterator->next(); diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index c27244797..aeec4521f 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -19,6 +19,10 @@ // // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif + #include "utilities.h" #include "SMDS_Mesh.hxx" #include "SMDS_VolumeOfNodes.hxx" @@ -27,13 +31,15 @@ #include "SMDS_FaceOfEdges.hxx" #include +#include using namespace std; /////////////////////////////////////////////////////////////////////////////// /// Create a new mesh object /////////////////////////////////////////////////////////////////////////////// SMDS_Mesh::SMDS_Mesh() - :myNodeIDFactory(new SMDS_MeshElementIDFactory()), + :myParent(NULL), + myNodeIDFactory(new SMDS_MeshElementIDFactory()), myElementIDFactory(new SMDS_MeshElementIDFactory()), myHasConstructionEdges(false), myHasConstructionFaces(false), myHasInverseElements(true) @@ -86,7 +92,7 @@ SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID) const SMDS_MeshElement *node = myNodeIDFactory->MeshElement(ID); if(!node){ SMDS_MeshNode * node=new SMDS_MeshNode(x, y, z); - myNodes.insert(node); + myNodes.Add(node); myNodeIDFactory->BindID(ID,node); return node; }else @@ -137,7 +143,7 @@ SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1, node2=const_cast(n2); node1->AddInverseElement(edge); node2->AddInverseElement(edge); - myEdges.insert(edge); + myEdges.Add(edge); return edge; } else { @@ -266,7 +272,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1, if (!hasConstructionEdges()) return NULL; SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3); - myFaces.insert(face); + myFaces.Add(face); if (!registerElement(ID, face)) { RemoveElement(face, false); @@ -303,7 +309,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1, if (!hasConstructionEdges()) return NULL; SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3,e4); - myFaces.insert(face); + myFaces.Add(face); if (!registerElement(ID, face)) { @@ -370,7 +376,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, SMDS_MeshFace * f3=FindFaceOrCreate(n1,n3,n4); SMDS_MeshFace * f4=FindFaceOrCreate(n2,n3,n4); volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4); - myVolumes.insert(volume); + myVolumes.Add(volume); } else if(hasConstructionEdges()) { MESSAGE("Error : Not implemented"); @@ -378,7 +384,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, } else { volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4); - myVolumes.insert(volume); + myVolumes.Add(volume); } if (!registerElement(ID, volume)) { @@ -452,7 +458,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, SMDS_MeshFace * f3=FindFaceOrCreate(n2,n3,n5); SMDS_MeshFace * f4=FindFaceOrCreate(n3,n4,n5); volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4); - myVolumes.insert(volume); + myVolumes.Add(volume); } else if(hasConstructionEdges()) { MESSAGE("Error : Not implemented"); @@ -460,7 +466,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, } else { volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5); - myVolumes.insert(volume); + myVolumes.Add(volume); } if (!registerElement(ID, volume)) { @@ -539,7 +545,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, SMDS_MeshFace * f4=FindFaceOrCreate(n2,n5,n6,n3); SMDS_MeshFace * f5=FindFaceOrCreate(n3,n6,n4,n1); volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5); - myVolumes.insert(volume); + myVolumes.Add(volume); } else if(hasConstructionEdges()) { MESSAGE("Error : Not implemented"); @@ -547,7 +553,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, } else { volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5,n6); - myVolumes.insert(volume); + myVolumes.Add(volume); } if (!registerElement(ID, volume)) { @@ -638,7 +644,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, SMDS_MeshFace * f5=FindFaceOrCreate(n2,n3,n7,n6); SMDS_MeshFace * f6=FindFaceOrCreate(n3,n4,n8,n7); volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6); - myVolumes.insert(volume); + myVolumes.Add(volume); } else if(hasConstructionEdges()) { MESSAGE("Error : Not implemented"); @@ -647,7 +653,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, else { // volume=new SMDS_HexahedronOfNodes(n1,n2,n3,n4,n5,n6,n7,n8); volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5,n6,n7,n8); - myVolumes.insert(volume); + myVolumes.Add(volume); } if (!registerElement(ID, volume)) { @@ -687,7 +693,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1, if (!hasConstructionFaces()) return NULL; SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4); - myVolumes.insert(volume); + myVolumes.Add(volume); if (!registerElement(ID, volume)) { RemoveElement(volume, false); @@ -728,7 +734,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1, if (!hasConstructionFaces()) return NULL; SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5); - myVolumes.insert(volume); + myVolumes.Add(volume); if (!registerElement(ID, volume)) { RemoveElement(volume, false); @@ -771,7 +777,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1, if (!hasConstructionFaces()) return NULL; SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6); - myVolumes.insert(volume); + myVolumes.Add(volume); if (!registerElement(ID, volume)) { RemoveElement(volume, false); @@ -821,13 +827,13 @@ SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1, edge3=FindEdgeOrCreate(node3,node1); SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3); - myFaces.insert(face); + myFaces.Add(face); return face; } else { SMDS_MeshFace * face = new SMDS_FaceOfNodes(node1,node2,node3); - myFaces.insert(face); + myFaces.Add(face); return face; } } @@ -850,13 +856,13 @@ SMDS_MeshFace * SMDS_Mesh::createQuadrangle(const SMDS_MeshNode * node1, edge4=FindEdgeOrCreate(node4,node1); SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3,edge4); - myFaces.insert(face); + myFaces.Add(face); return face; } else { SMDS_MeshFace * face = new SMDS_FaceOfNodes(node1,node2,node3,node4); - myFaces.insert(face); + myFaces.Add(face); return face; } } @@ -1051,7 +1057,7 @@ SMDS_MeshEdge* SMDS_Mesh::FindEdgeOrCreate(const SMDS_MeshNode * node1, if(toReturn==NULL) { toReturn=new SMDS_MeshEdge(node1,node2); - myEdges.insert(toReturn); + myEdges.Add(toReturn); } return toReturn; } @@ -1289,7 +1295,7 @@ void SMDS_Mesh::DebugStats() const /////////////////////////////////////////////////////////////////////////////// int SMDS_Mesh::NbNodes() const { - return myNodes.size(); + return myNodes.Size(); } /////////////////////////////////////////////////////////////////////////////// @@ -1297,7 +1303,7 @@ int SMDS_Mesh::NbNodes() const /////////////////////////////////////////////////////////////////////////////// int SMDS_Mesh::NbEdges() const { - return myEdges.size(); + return myEdges.Size(); } /////////////////////////////////////////////////////////////////////////////// @@ -1305,7 +1311,7 @@ int SMDS_Mesh::NbEdges() const /////////////////////////////////////////////////////////////////////////////// int SMDS_Mesh::NbFaces() const { - return myFaces.size(); + return myFaces.Size(); } /////////////////////////////////////////////////////////////////////////////// @@ -1313,7 +1319,7 @@ int SMDS_Mesh::NbFaces() const /////////////////////////////////////////////////////////////////////////////// int SMDS_Mesh::NbVolumes() const { - return myVolumes.size(); + return myVolumes.Size(); } /////////////////////////////////////////////////////////////////////////////// @@ -1332,45 +1338,49 @@ int SMDS_Mesh::NbSubMesh() const /////////////////////////////////////////////////////////////////////////////// SMDS_Mesh::~SMDS_Mesh() { - if(myParent==NULL) - { - delete myNodeIDFactory; - delete myElementIDFactory; - } + list::iterator itc=myChildren.begin(); + while(itc!=myChildren.end()) + { + delete *itc; + itc++; + } - list::iterator itc=myChildren.begin(); - while(itc!=myChildren.end()) - { - delete *itc; - itc++; - } - - SMDS_NodeIteratorPtr itn=nodesIterator(); - while(itn->more()) - { - delete itn->next(); - } + SetOfNodes::Iterator itn(myNodes); + for (; itn.More(); itn.Next()) + delete itn.Value(); - set::iterator ite=myEdges.begin(); - while(ite!=myEdges.end()) - { - delete *ite; - ite++; - } + SetOfEdges::Iterator ite(myEdges); + for (; ite.More(); ite.Next()) + { + SMDS_MeshElement* elem = ite.Value(); + if(myParent!=NULL) + myElementIDFactory->ReleaseID(elem->GetID()); + delete elem; + } - set::iterator itf=myFaces.begin(); - while(itf!=myFaces.end()) - { - delete *itf; - itf++; - } + SetOfFaces::Iterator itf(myFaces); + for (; itf.More(); itf.Next()) + { + SMDS_MeshElement* elem = itf.Value(); + if(myParent!=NULL) + myElementIDFactory->ReleaseID(elem->GetID()); + delete elem; + } - set::iterator itv=myVolumes.begin(); - while(itv!=myVolumes.end()) - { - delete *itv; - itv++; - } + SetOfVolumes::Iterator itv(myVolumes); + for (; itv.More(); itv.Next()) + { + SMDS_MeshElement* elem = itv.Value(); + if(myParent!=NULL) + myElementIDFactory->ReleaseID(elem->GetID()); + delete elem; + } + + if(myParent==NULL) + { + delete myNodeIDFactory; + delete myElementIDFactory; + } } /////////////////////////////////////////////////////////////////////////////// @@ -1433,100 +1443,68 @@ void SMDS_Mesh::setInverseElements(bool b) } /////////////////////////////////////////////////////////////////////////////// -/// Return an iterator on nodes of the current mesh +/// Return an iterator on nodes of the current mesh factory /////////////////////////////////////////////////////////////////////////////// class SMDS_Mesh_MyNodeIterator:public SMDS_NodeIterator { - const SMDS_IdElementMap& myIdElemMap; - SMDS_IdElementMap::const_iterator myIterator; + SMDS_ElemIteratorPtr myIterator; public: - SMDS_Mesh_MyNodeIterator(const SMDS_IdElementMap& s):myIdElemMap(s) - { - myIterator=myIdElemMap.begin(); - } + SMDS_Mesh_MyNodeIterator(const SMDS_ElemIteratorPtr& it):myIterator(it) + {} bool more() { - return myIterator!=myIdElemMap.end(); + return myIterator->more(); } const SMDS_MeshNode* next() { - const SMDS_MeshElement* current=(*myIterator).second; - myIterator++; - return static_cast( current ); + return static_cast(myIterator->next()); } }; SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator() const { return SMDS_NodeIteratorPtr - (new SMDS_Mesh_MyNodeIterator(myNodeIDFactory->GetIdElementMap())); + (new SMDS_Mesh_MyNodeIterator(myNodeIDFactory->elementsIterator())); } + /////////////////////////////////////////////////////////////////////////////// -/// Return an iterator on nodes of the current mesh +/// Return an iterator on elements of the current mesh factory /////////////////////////////////////////////////////////////////////////////// -class SMDS_Mesh_MyElemIterator:public SMDS_ElemIterator -{ - const SMDS_IdElementMap& myIdElemMap; - SMDS_IdElementMap::const_iterator myIterator; - public: - SMDS_Mesh_MyElemIterator(const SMDS_IdElementMap& s):myIdElemMap(s) - { - myIterator=myIdElemMap.begin(); - } - - bool more() - { - return myIterator!=myIdElemMap.end(); - } - - const SMDS_MeshElement* next() - { - const SMDS_MeshElement* current=(*myIterator).second; - myIterator++; - return current; - } -}; - SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator() const { - return SMDS_ElemIteratorPtr - (new SMDS_Mesh_MyElemIterator(myElementIDFactory->GetIdElementMap())); + return myElementIDFactory->elementsIterator(); } /////////////////////////////////////////////////////////////////////////////// -///Return an iterator on volumes of the current mesh. +///Return an iterator on edges of the current mesh. /////////////////////////////////////////////////////////////////////////////// class SMDS_Mesh_MyEdgeIterator:public SMDS_EdgeIterator { typedef SMDS_Mesh::SetOfEdges SetOfEdges; - const SetOfEdges& mySet; - const SMDS_MeshEdge * myEdge; - SetOfEdges::iterator myIterator; + SetOfEdges::Iterator myIterator; public: - SMDS_Mesh_MyEdgeIterator(const SetOfEdges& s):mySet(s) - { - myIterator=mySet.begin(); - } + SMDS_Mesh_MyEdgeIterator(const SetOfEdges& s):myIterator(s) + {} bool more() { - while((myIterator!=mySet.end())) + while(myIterator.More()) { - if((*myIterator)->GetID()!=-1) + if(myIterator.Value()->GetID()!=-1) return true; - myIterator++; + myIterator.Next(); } return false; } const SMDS_MeshEdge* next() { - const SMDS_MeshEdge* current=*myIterator; - myIterator++; - return current; - } + const SMDS_MeshEdge* current = myIterator.Value(); + myIterator.Next(); + return current; + } }; SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator() const @@ -1535,37 +1513,33 @@ SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator() const } /////////////////////////////////////////////////////////////////////////////// -///Return an iterator on faces of the current mesh. Once used this iterator -///must be free by the caller +///Return an iterator on faces of the current mesh. /////////////////////////////////////////////////////////////////////////////// class SMDS_Mesh_MyFaceIterator:public SMDS_FaceIterator { typedef SMDS_Mesh::SetOfFaces SetOfFaces; - const SetOfFaces& mySet; - SetOfFaces::iterator myIterator; + SetOfFaces::Iterator myIterator; public: - SMDS_Mesh_MyFaceIterator(const SetOfFaces& s):mySet(s) - { - myIterator=mySet.begin(); - } + SMDS_Mesh_MyFaceIterator(const SetOfFaces& s):myIterator(s) + {} bool more() { - while((myIterator!=mySet.end())) + while(myIterator.More()) { - if((*myIterator)->GetID()!=-1) + if(myIterator.Value()->GetID()!=-1) return true; - myIterator++; + myIterator.Next(); } return false; } const SMDS_MeshFace* next() { - const SMDS_MeshFace* current=*myIterator; - myIterator++; - return current; - } + const SMDS_MeshFace* current = myIterator.Value(); + myIterator.Next(); + return current; + } }; SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator() const @@ -1574,31 +1548,27 @@ SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator() const } /////////////////////////////////////////////////////////////////////////////// -///Return an iterator on volumes of the current mesh. Once used this iterator -///must be free by the caller +///Return an iterator on volumes of the current mesh. /////////////////////////////////////////////////////////////////////////////// class SMDS_Mesh_MyVolumeIterator:public SMDS_VolumeIterator { typedef SMDS_Mesh::SetOfVolumes SetOfVolumes; - const SetOfVolumes& mySet; - SetOfVolumes::iterator myIterator; + SetOfVolumes::Iterator myIterator; public: - SMDS_Mesh_MyVolumeIterator(const SetOfVolumes& s):mySet(s) - { - myIterator=mySet.begin(); - } + SMDS_Mesh_MyVolumeIterator(const SetOfVolumes& s):myIterator(s) + {} bool more() { - return myIterator!=mySet.end(); + return myIterator.More() != Standard_False; } const SMDS_MeshVolume* next() { - const SMDS_MeshVolume* current=*myIterator; - myIterator++; - return current; - } + const SMDS_MeshVolume* current = myIterator.Value(); + myIterator.Next(); + return current; + } }; SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator() const @@ -1634,7 +1604,9 @@ static set * intersectionOfSets( static set * getFinitElements(const SMDS_MeshElement * element) { int numberOfSets=element->NbNodes(); - set initSet[numberOfSets]; + auto_ptr > pInitSet + (new set[numberOfSets]); + set *initSet = &(*pInitSet); SMDS_ElemIteratorPtr itNodes=element->nodesIterator(); @@ -1822,15 +1794,15 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, MESSAGE("Internal Error: This should not happen"); break; case SMDSAbs_Edge: - myEdges.erase(static_cast + myEdges.Remove(static_cast (const_cast(*it))); break; case SMDSAbs_Face: - myFaces.erase(static_cast + myFaces.Remove(static_cast (const_cast(*it))); break; case SMDSAbs_Volume: - myVolumes.erase(static_cast + myVolumes.Remove(static_cast (const_cast(*it))); break; } @@ -1848,7 +1820,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, while(it!=s2->end()) { //MESSAGE( "SMDS: RM node " << (*it)->GetID() ); - myNodes.erase(static_cast + myNodes.Remove(static_cast (const_cast(*it))); myNodeIDFactory->ReleaseID((*it)->GetID()); removedNodes.push_back( (*it) ); @@ -1941,23 +1913,27 @@ void SMDS_Mesh::Renumber (const bool isNodes, const int startID, const int del SMDS_MeshElementIDFactory * idFactory = isNodes ? myNodeIDFactory : myElementIDFactory; - // get existing elements in the order of ID increasing and release their ids - list< SMDS_MeshElement * > elemList; - const SMDS_IdElementMap& idElemMap = idFactory->GetIdElementMap(); - SMDS_IdElementMap::const_iterator idElemIt = idElemMap.begin(); - while ( idElemIt != idElemMap.end() ) { - SMDS_MeshElement* elem = (*idElemIt).second; - int id = (*idElemIt).first; - idElemIt++; - elemList.push_back( elem ); + // get existing elements in the order of ID increasing + map elemMap; + SMDS_ElemIteratorPtr idElemIt = idFactory->elementsIterator(); + while ( idElemIt->more() ) { + SMDS_MeshElement* elem = const_cast(idElemIt->next()); + int id = elem->GetID(); + elemMap.insert(map::value_type(id, elem)); + } + // release their ids + map::iterator elemIt = elemMap.begin(); + for ( ; elemIt != elemMap.end(); elemIt++ ) + { + int id = (*elemIt).first; idFactory->ReleaseID( id ); } // set new IDs int ID = startID; - list< SMDS_MeshElement * >::iterator elemIt = elemList.begin(); - for ( ; elemIt != elemList.end(); elemIt++ ) + elemIt = elemMap.begin(); + for ( ; elemIt != elemMap.end(); elemIt++ ) { - idFactory->BindID( ID, *elemIt ); + idFactory->BindID( ID, (*elemIt).second ); ID += deltaID; } } diff --git a/src/SMDS/SMDS_Mesh.hxx b/src/SMDS/SMDS_Mesh.hxx index cdcc9166b..1aa9dda92 100644 --- a/src/SMDS/SMDS_Mesh.hxx +++ b/src/SMDS/SMDS_Mesh.hxx @@ -32,7 +32,8 @@ #include "SMDS_MeshFace.hxx" #include "SMDS_MeshVolume.hxx" #include "SMDS_MeshElementIDFactory.hxx" -#include "SMDS_Iterator.hxx" +#include "SMDS_ElemIterator.hxx" +#include #include #include @@ -268,10 +269,10 @@ public: */ bool Contains (const SMDS_MeshElement* elem) const; - typedef std::set SetOfNodes; - typedef std::set SetOfEdges; - typedef std::set SetOfFaces; - typedef std::set SetOfVolumes; + typedef NCollection_Map SetOfNodes; + typedef NCollection_Map SetOfEdges; + typedef NCollection_Map SetOfFaces; + typedef NCollection_Map SetOfVolumes; private: SMDS_Mesh(SMDS_Mesh * parent); diff --git a/src/SMDS/SMDS_MeshEdge.cxx b/src/SMDS/SMDS_MeshEdge.cxx index 640723147..66c8ae3d5 100644 --- a/src/SMDS/SMDS_MeshEdge.cxx +++ b/src/SMDS/SMDS_MeshEdge.cxx @@ -25,6 +25,9 @@ // Author : Jean-Michel BOULCOURT // Module : SMESH +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif #include "SMDS_MeshEdge.hxx" #include "SMDS_IteratorOfElements.hxx" diff --git a/src/SMDS/SMDS_MeshElement.cxx b/src/SMDS/SMDS_MeshElement.cxx index bf4564f90..8d4d9b75d 100644 --- a/src/SMDS/SMDS_MeshElement.cxx +++ b/src/SMDS/SMDS_MeshElement.cxx @@ -19,6 +19,10 @@ // // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif + #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" #include "SMDS_MeshEdge.hxx" diff --git a/src/SMDS/SMDS_MeshElement.hxx b/src/SMDS/SMDS_MeshElement.hxx index 607ab3caf..3d9d13afe 100644 --- a/src/SMDS/SMDS_MeshElement.hxx +++ b/src/SMDS/SMDS_MeshElement.hxx @@ -29,20 +29,15 @@ #include "SMDSAbs_ElementType.hxx" #include "SMDS_MeshObject.hxx" -#include "SMDS_Iterator.hxx" +#include "SMDS_ElemIterator.hxx" #include "SMDS_MeshElementIDFactory.hxx" -#include #include #include class SMDS_MeshNode; class SMDS_MeshEdge; class SMDS_MeshFace; -class SMDS_MeshElement; - -typedef SMDS_Iterator SMDS_ElemIterator; -typedef boost::shared_ptr > SMDS_ElemIteratorPtr; /////////////////////////////////////////////////////////////////////////////// /// Base class for elements diff --git a/src/SMDS/SMDS_MeshElementIDFactory.cxx b/src/SMDS/SMDS_MeshElementIDFactory.cxx index 456d16a15..8fc09230b 100644 --- a/src/SMDS/SMDS_MeshElementIDFactory.cxx +++ b/src/SMDS/SMDS_MeshElementIDFactory.cxx @@ -25,6 +25,9 @@ // Author : Jean-Michel BOULCOURT // Module : SMESH +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif #include "SMDS_MeshElementIDFactory.hxx" #include "SMDS_MeshElement.hxx" @@ -35,7 +38,9 @@ using namespace std; //function : SMDS_MeshElementIDFactory //purpose : //======================================================================= -SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory():SMDS_MeshIDFactory() +SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory(): + SMDS_MeshIDFactory(), + myMin(0), myMax(0) { } @@ -45,10 +50,12 @@ SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory():SMDS_MeshIDFactory() //======================================================================= bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem) { - bool bound=myIDElements.insert( - map::value_type(ID,elem)).second; - if(bound) elem->myID=ID; - return bound; + if (myIDElements.IsBound(ID)) + return false; + myIDElements.Bind(ID,elem); + elem->myID=ID; + updateMinMax (ID); + return true; } //======================================================================= @@ -57,8 +64,9 @@ bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem) //======================================================================= SMDS_MeshElement* SMDS_MeshElementIDFactory::MeshElement(int ID) { - map::iterator it=myIDElements.find(ID); - if(it==myIDElements.end()) return NULL; else return (*it).second; + if (!myIDElements.IsBound(ID)) + return NULL; + return myIDElements.Find(ID); } @@ -71,7 +79,7 @@ int SMDS_MeshElementIDFactory::GetFreeID() int ID; do { ID = SMDS_MeshIDFactory::GetFreeID(); - } while (myIDElements.find(ID) != myIDElements.end()); + } while (myIDElements.IsBound(ID)); return ID; } @@ -81,8 +89,12 @@ int SMDS_MeshElementIDFactory::GetFreeID() //======================================================================= void SMDS_MeshElementIDFactory::ReleaseID(const int ID) { - myIDElements.erase(ID); + myIDElements.UnBind(ID); SMDS_MeshIDFactory::ReleaseID(ID); + if (ID == myMax) + myMax = 0; + if (ID == myMin) + myMin = 0; } //======================================================================= @@ -92,11 +104,9 @@ void SMDS_MeshElementIDFactory::ReleaseID(const int ID) int SMDS_MeshElementIDFactory::GetMaxID() const { - map::const_reverse_iterator it = myIDElements.rbegin(); - if ( it != myIDElements.rend() ) - return (*it).first; - - return 0; + if (myMax == 0) + updateMinMax(); + return myMax; } //======================================================================= @@ -106,10 +116,54 @@ int SMDS_MeshElementIDFactory::GetMaxID() const int SMDS_MeshElementIDFactory::GetMinID() const { - map::const_iterator it = myIDElements.begin(); - if ( it != myIDElements.end() ) - return (*it).first; + if (myMin == 0) + updateMinMax(); + return myMin; +} - return 0; +//======================================================================= +//function : updateMinMax +//purpose : +//======================================================================= + +void SMDS_MeshElementIDFactory::updateMinMax() const +{ + myMin = IntegerLast(); + myMax = 0; + SMDS_IdElementMap::Iterator it(myIDElements); + for (; it.More(); it.Next()) + updateMinMax (it.Key()); + if (myMin == IntegerLast()) + myMin = 0; } +//======================================================================= +//function : elementsIterator +//purpose : Return an iterator on elements of the factory +//======================================================================= + +class SMDS_Fact_MyElemIterator:public SMDS_ElemIterator +{ + SMDS_IdElementMap::Iterator myIterator; + public: + SMDS_Fact_MyElemIterator(const SMDS_IdElementMap& s):myIterator(s) + {} + + bool more() + { + return myIterator.More() != Standard_False; + } + + const SMDS_MeshElement* next() + { + const SMDS_MeshElement* current = myIterator.Value(); + myIterator.Next(); + return current; + } +}; + +SMDS_ElemIteratorPtr SMDS_MeshElementIDFactory::elementsIterator() const +{ + return SMDS_ElemIteratorPtr + (new SMDS_Fact_MyElemIterator(myIDElements)); +} diff --git a/src/SMDS/SMDS_MeshElementIDFactory.hxx b/src/SMDS/SMDS_MeshElementIDFactory.hxx index 932ad057c..526bcb5a0 100644 --- a/src/SMDS/SMDS_MeshElementIDFactory.hxx +++ b/src/SMDS/SMDS_MeshElementIDFactory.hxx @@ -28,26 +28,35 @@ #define _SMDS_MeshElementIDFactory_HeaderFile #include "SMDS_MeshIDFactory.hxx" +#include "SMDS_ElemIterator.hxx" -#include +#include class SMDS_MeshElement; -typedef std::map SMDS_IdElementMap; +typedef NCollection_DataMap SMDS_IdElementMap; class SMDS_MeshElementIDFactory:public SMDS_MeshIDFactory { - public: - SMDS_MeshElementIDFactory(); - bool BindID(int ID, SMDS_MeshElement * elem); - SMDS_MeshElement * MeshElement(int ID); - virtual int GetFreeID(); - virtual void ReleaseID(int ID); - int GetMaxID() const; - int GetMinID() const; - const SMDS_IdElementMap & GetIdElementMap() const { return myIDElements; } - private: - SMDS_IdElementMap myIDElements; +public: + SMDS_MeshElementIDFactory(); + bool BindID(int ID, SMDS_MeshElement * elem); + SMDS_MeshElement * MeshElement(int ID); + virtual int GetFreeID(); + virtual void ReleaseID(int ID); + int GetMaxID() const; + int GetMinID() const; + SMDS_ElemIteratorPtr elementsIterator() const; +private: + void updateMinMax() const; + void updateMinMax(int id) const + { + if (id > myMax) myMax = id; + if (id < myMin) myMin = id; + } + + SMDS_IdElementMap myIDElements; + mutable int myMin, myMax; }; diff --git a/src/SMDS/SMDS_MeshGroup.cxx b/src/SMDS/SMDS_MeshGroup.cxx index 6a255e152..0acb246a8 100644 --- a/src/SMDS/SMDS_MeshGroup.cxx +++ b/src/SMDS/SMDS_MeshGroup.cxx @@ -24,6 +24,10 @@ // Author : Jean-Michel BOULCOURT // Module : SMESH +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif + #include "SMDS_MeshGroup.hxx" #include "utilities.h" diff --git a/src/SMDS/SMDS_MeshGroup.hxx b/src/SMDS/SMDS_MeshGroup.hxx index 69084c5b9..ef2264c12 100644 --- a/src/SMDS/SMDS_MeshGroup.hxx +++ b/src/SMDS/SMDS_MeshGroup.hxx @@ -65,7 +65,7 @@ class SMDS_MeshGroup:public SMDS_MeshObject SMDS_MeshGroup(SMDS_MeshGroup* theParent, const SMDSAbs_ElementType theType = SMDSAbs_All); - typedef std::set::iterator TIterator; + typedef std::set::const_iterator TIterator; const SMDS_Mesh * myMesh; SMDSAbs_ElementType myType; std::set myElements; diff --git a/src/SMDS/SMDS_MeshNode.cxx b/src/SMDS/SMDS_MeshNode.cxx index c672fe702..06ab12173 100644 --- a/src/SMDS/SMDS_MeshNode.cxx +++ b/src/SMDS/SMDS_MeshNode.cxx @@ -19,6 +19,9 @@ // // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif #include "SMDS_MeshNode.hxx" #include "SMDS_SpacePosition.hxx" @@ -44,7 +47,14 @@ SMDS_MeshNode::SMDS_MeshNode(double x, double y, double z): void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * parent) { - myInverseElements.erase(parent); + NCollection_List::Iterator it(myInverseElements); + while (it.More()) { + const SMDS_MeshElement* elem = it.Value(); + if (elem == parent) + myInverseElements.Remove(it); + else + it.Next(); + } } //======================================================================= @@ -80,25 +90,22 @@ const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const class SMDS_MeshNode_MyInvIterator:public SMDS_ElemIterator { - const set& mySet; - set::iterator myIterator; + NCollection_List::Iterator myIterator; public: - SMDS_MeshNode_MyInvIterator(const set& s): - mySet(s) - { - myIterator=mySet.begin(); - } + SMDS_MeshNode_MyInvIterator(const NCollection_List& s): + myIterator(s) + {} bool more() { - return myIterator!=mySet.end(); + return myIterator.More() != Standard_False; } const SMDS_MeshElement* next() { - const SMDS_MeshElement* current=*myIterator; - myIterator++; - return current; + const SMDS_MeshElement* current=myIterator.Value(); + myIterator.Next(); + return current; } }; @@ -112,39 +119,38 @@ SMDS_ElemIteratorPtr SMDS_MeshNode:: // wanted type elements. class SMDS_MeshNode_MyIterator:public SMDS_ElemIterator { - set mySet; - set::iterator myIterator; + NCollection_List mySet; + NCollection_List::Iterator myIterator; public: SMDS_MeshNode_MyIterator(SMDSAbs_ElementType type, - const set& s) + const NCollection_List& s) { const SMDS_MeshElement * e; bool toInsert; - set::iterator it=s.begin(); - while(it!=s.end()) + NCollection_List::Iterator it(s); + for(; it.More(); it.Next()) { - e=*it; + e=it.Value(); switch(type) { case SMDSAbs_Edge: toInsert=true; break; case SMDSAbs_Face: toInsert=(e->GetType()!=SMDSAbs_Edge); break; case SMDSAbs_Volume: toInsert=(e->GetType()==SMDSAbs_Volume); break; } - if(toInsert) mySet.insert(e); - it++; + if(toInsert) mySet.Append(e); } - myIterator=mySet.begin(); + myIterator.Init(mySet); } bool more() { - return myIterator!=mySet.end(); + return myIterator.More() != Standard_False; } const SMDS_MeshElement* next() { - const SMDS_MeshElement* current=*myIterator; - myIterator++; + const SMDS_MeshElement* current=myIterator.Value(); + myIterator.Next(); return current; } }; @@ -199,7 +205,13 @@ SMDSAbs_ElementType SMDS_MeshNode::GetType() const //======================================================================= void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME) { - myInverseElements.insert(ME); + NCollection_List::Iterator it(myInverseElements); + for (; it.More(); it.Next()) { + const SMDS_MeshElement* elem = it.Value(); + if (elem == ME) + return; + } + myInverseElements.Append(ME); } //======================================================================= @@ -208,12 +220,12 @@ void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME) //======================================================================= void SMDS_MeshNode::ClearInverseElements() { - myInverseElements.clear(); + myInverseElements.Clear(); } bool SMDS_MeshNode::emptyInverseElements() { - return myInverseElements.empty(); + return myInverseElements.IsEmpty() != Standard_False; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/SMDS/SMDS_MeshNode.hxx b/src/SMDS/SMDS_MeshNode.hxx index e4ecc1f5c..fec75242e 100644 --- a/src/SMDS/SMDS_MeshNode.hxx +++ b/src/SMDS/SMDS_MeshNode.hxx @@ -29,9 +29,7 @@ #include "SMDS_MeshElement.hxx" #include "SMDS_Position.hxx" - -#include - +#include class SMDS_MeshNode:public SMDS_MeshElement { @@ -61,7 +59,7 @@ class SMDS_MeshNode:public SMDS_MeshElement private: double myX, myY, myZ; SMDS_PositionPtr myPosition; - std::set myInverseElements; + NCollection_List myInverseElements; }; #endif diff --git a/src/SMDS/SMDS_VertexPosition.cxx b/src/SMDS/SMDS_VertexPosition.cxx index 94b12438c..022f76ad3 100644 --- a/src/SMDS/SMDS_VertexPosition.cxx +++ b/src/SMDS/SMDS_VertexPosition.cxx @@ -49,7 +49,7 @@ SMDS_VertexPosition:: SMDS_VertexPosition(const int aVertexId) const double *SMDS_VertexPosition::Coords() const { const static double origin[]={0,0,0}; - MESSAGE("SMDS_EdgePosition::Coords not implemented"); + MESSAGE("SMDS_VertexPosition::Coords not implemented"); return origin; } diff --git a/src/SMDS/SMDS_VolumeOfFaces.cxx b/src/SMDS/SMDS_VolumeOfFaces.cxx index a710a8ffe..51e71f86c 100644 --- a/src/SMDS/SMDS_VolumeOfFaces.cxx +++ b/src/SMDS/SMDS_VolumeOfFaces.cxx @@ -25,6 +25,10 @@ // Author : Jean-Michel BOULCOURT // Module : SMESH +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif + #include "SMDS_VolumeOfFaces.hxx" #include "SMDS_IteratorOfElements.hxx" @@ -39,27 +43,28 @@ void SMDS_VolumeOfFaces::Print(ostream & OS) const { OS << "volume <" << GetID() << "> : "; int i; - for (i = 0; i < myFaces.size()-1; ++i) OS << myFaces[i] << ","; + for (i = 0; i < NbFaces()-1; ++i) OS << myFaces[i] << ","; OS << myFaces[i]<< ") " << endl; } int SMDS_VolumeOfFaces::NbFaces() const { - return myFaces.size(); + return myNbFaces; } class SMDS_VolumeOfFaces_MyIterator:public SMDS_ElemIterator { - const vector& mySet; + const SMDS_MeshFace* const *mySet; + int myLength; int index; public: - SMDS_VolumeOfFaces_MyIterator(const vector& s): - mySet(s),index(0) {} + SMDS_VolumeOfFaces_MyIterator(const SMDS_MeshFace* const *s, int l): + mySet(s),myLength(l),index(0) {} bool more() { - return index #include @@ -61,6 +60,7 @@ class SMDS_VolumeOfFaces:public SMDS_MeshVolume protected: SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; - std::vector myFaces; + const SMDS_MeshFace * myFaces[6]; + int myNbFaces; }; #endif diff --git a/src/SMDS/SMDS_VolumeOfNodes.cxx b/src/SMDS/SMDS_VolumeOfNodes.cxx index 25c0bf567..cd893f484 100644 --- a/src/SMDS/SMDS_VolumeOfNodes.cxx +++ b/src/SMDS/SMDS_VolumeOfNodes.cxx @@ -19,6 +19,10 @@ // // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif + #include "SMDS_VolumeOfNodes.hxx" #include "SMDS_MeshNode.hxx" #include "utilities.h" @@ -39,7 +43,8 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes( const SMDS_MeshNode * node7, const SMDS_MeshNode * node8) { - myNodes.resize(8); + myNbNodes = 8; + myNodes = new const SMDS_MeshNode* [myNbNodes]; myNodes[0]=node1; myNodes[1]=node2; myNodes[2]=node3; @@ -56,7 +61,8 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes( const SMDS_MeshNode * node3, const SMDS_MeshNode * node4) { - myNodes.resize(4); + myNbNodes = 4; + myNodes = new const SMDS_MeshNode* [myNbNodes]; myNodes[0]=node1; myNodes[1]=node2; myNodes[2]=node3; @@ -70,7 +76,8 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes( const SMDS_MeshNode * node4, const SMDS_MeshNode * node5) { - myNodes.resize(5); + myNbNodes = 5; + myNodes = new const SMDS_MeshNode* [myNbNodes]; myNodes[0]=node1; myNodes[1]=node2; myNodes[2]=node3; @@ -86,7 +93,8 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes( const SMDS_MeshNode * node5, const SMDS_MeshNode * node6) { - myNodes.resize(6); + myNbNodes = 6; + myNodes = new const SMDS_MeshNode* [myNbNodes]; myNodes[0]=node1; myNodes[1]=node2; myNodes[2]=node3; @@ -94,18 +102,30 @@ SMDS_VolumeOfNodes::SMDS_VolumeOfNodes( myNodes[4]=node5; myNodes[5]=node6; } + bool SMDS_VolumeOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) { if (nbNodes < 4 || nbNodes > 8 || nbNodes == 7) return false; - myNodes.resize( nbNodes ); + delete [] myNodes; + myNbNodes = nbNodes; + myNodes = new const SMDS_MeshNode* [myNbNodes]; for ( int i = 0; i < nbNodes; i++ ) myNodes[ i ] = nodes [ i ]; return true; } + +SMDS_VolumeOfNodes::~SMDS_VolumeOfNodes() +{ + if (myNodes != NULL) { + delete [] myNodes; + myNodes = NULL; + } +} + //======================================================================= //function : Print //purpose : @@ -134,7 +154,7 @@ int SMDS_VolumeOfNodes::NbFaces() const int SMDS_VolumeOfNodes::NbNodes() const { - return myNodes.size(); + return myNbNodes; } int SMDS_VolumeOfNodes::NbEdges() const @@ -152,15 +172,16 @@ int SMDS_VolumeOfNodes::NbEdges() const class SMDS_VolumeOfNodes_MyIterator:public SMDS_ElemIterator { - const vector& mySet; + const SMDS_MeshNode* const* mySet; + int myLength; int index; public: - SMDS_VolumeOfNodes_MyIterator(const vector& s): - mySet(s),index(0) {} + SMDS_VolumeOfNodes_MyIterator(const SMDS_MeshNode* const* s, int l): + mySet(s),myLength(l),index(0) {} bool more() { - return index class SMDS_VolumeOfNodes:public SMDS_MeshVolume @@ -64,6 +63,7 @@ class SMDS_VolumeOfNodes:public SMDS_MeshVolume const SMDS_MeshNode * node8); bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes); + ~SMDS_VolumeOfNodes(); void Print(std::ostream & OS) const; int NbFaces() const; @@ -73,6 +73,7 @@ class SMDS_VolumeOfNodes:public SMDS_MeshVolume protected: SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; - std::vector myNodes; + const SMDS_MeshNode** myNodes; + int myNbNodes; }; #endif diff --git a/src/SMDS/SMDS_VolumeTool.cxx b/src/SMDS/SMDS_VolumeTool.cxx index 7acb3f054..034486801 100644 --- a/src/SMDS/SMDS_VolumeTool.cxx +++ b/src/SMDS/SMDS_VolumeTool.cxx @@ -3,6 +3,9 @@ // Author : Edward AGAPOV (eap) // Copyright : Open CASCADE +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif #include "SMDS_VolumeTool.hxx" @@ -10,35 +13,69 @@ #include "SMDS_MeshNode.hxx" #include #include +#include using namespace std; +// ====================================================== +// Node indices in faces depending on volume orientation +// making most faces normals external +// ====================================================== + /* // N3 // + // /|\ // / | \ // / | \ -// N0 +---|---+ N2 TETRAHEDRON +// N0 +---|---+ N1 TETRAHEDRON // \ | / // \ | / // \ | / // \|/ // + -// N1 +// N2 */ -static int Tetra_F [4][4] = { // FORWARD == REVERSED EXTERNAL - { 0, 1, 2, 0 }, // Bottom face has an internal normal, other - external +static int Tetra_F [4][4] = { // FORWARD == EXTERNAL + { 0, 1, 2, 0 }, // All faces have external normals + { 0, 3, 1, 0 }, + { 1, 3, 2, 1 }, + { 0, 2, 3, 0 }}; +static int Tetra_R [4][4] = { // REVERSED + { 0, 1, 2, 0 }, // All faces but a bottom have external normals { 0, 1, 3, 0 }, { 1, 2, 3, 1 }, - { 0, 3, 2, 0 }}; -static int Tetra_R [4][4] = { // REVERSED == FORWARD EXTERNAL - { 0, 2, 1, 0 }, // All faces have external normals + { 0, 3, 2, 0 }}; +static int Tetra_RE [4][4] = { // REVERSED -> FORWARD (EXTERNAL) + { 0, 2, 1, 0 }, // All faces have external normals { 0, 1, 3, 0 }, { 1, 2, 3, 1 }, - { 0, 3, 2, 0 }}; + { 0, 3, 2, 0 }}; static int Tetra_nbN [] = { 3, 3, 3, 3 }; +// +// PYRAMID +// +static int Pyramid_F [5][5] = { // FORWARD == EXTERNAL + { 0, 1, 2, 3, 0 }, // All faces have external normals + { 0, 4, 1, 0, 4 }, + { 1, 4, 2, 1, 4 }, + { 2, 4, 3, 2, 4 }, + { 3, 4, 0, 3, 4 }}; +static int Pyramid_R [5][5] = { // REVERSED + { 0, 1, 2, 3, 0 }, // All faces but a bottom have external normals + { 0, 1, 4, 0, 4 }, + { 1, 2, 4, 1, 4 }, + { 2, 3, 4, 2, 4 }, + { 3, 0, 4, 3, 4 }}; +static int Pyramid_RE [5][5] = { // REVERSED -> FORWARD (EXTERNAL) + { 0, 3, 2, 1, 0 }, // All faces but a bottom have external normals + { 0, 1, 4, 0, 4 }, + { 1, 2, 4, 1, 4 }, + { 2, 3, 4, 2, 4 }, + { 3, 0, 4, 3, 4 }}; +static int Pyramid_nbN [] = { 4, 3, 3, 3, 3 }; + /* // + N4 // /|\ @@ -58,71 +95,71 @@ static int Penta_F [5][5] = { // FORWARD { 0, 1, 2, 0, 0 }, // Top face has an internal normal, other - external { 3, 4, 5, 3, 3 }, // 0 is bottom, 1 is top face { 0, 2, 5, 3, 0 }, - { 1, 2, 5, 4, 1 }, - { 1, 0, 3, 4, 1 }}; + { 1, 4, 5, 2, 1 }, + { 0, 3, 4, 1, 0 }}; static int Penta_R [5][5] = { // REVERSED - { 0, 2, 1, 0, 0 }, // Bottom face has an internal normal, other - external - { 3, 5, 4, 3, 3 }, // 0 is bottom, 1 is top face - { 0, 2, 5, 3, 0 }, + { 0, 1, 2, 0, 0 }, // Bottom face has an internal normal, other - external + { 3, 4, 5, 3, 3 }, // 0 is bottom, 1 is top face + { 0, 3, 5, 2, 0 }, { 1, 2, 5, 4, 1 }, - { 1, 0, 3, 4, 1 }}; -static int Penta_FE [5][5] = { // EXTERNAL + { 0, 1, 4, 3, 0 }}; +static int Penta_FE [5][5] = { // FORWARD -> EXTERNAL { 0, 1, 2, 0, 0 }, { 3, 5, 4, 3, 3 }, { 0, 2, 5, 3, 0 }, + { 1, 4, 5, 2, 1 }, + { 0, 3, 4, 1, 0 }}; +static int Penta_RE [5][5] = { // REVERSED -> EXTERNAL + { 0, 2, 1, 0, 0 }, + { 3, 4, 5, 3, 3 }, + { 0, 3, 5, 2, 0 }, { 1, 2, 5, 4, 1 }, - { 1, 0, 3, 4, 1 }}; -static int Penta_RE [5][5] = { // REVERSED EXTERNAL - { 0, 0, 2, 1, 0 }, - { 3, 3, 4, 5, 3 }, - { 0, 2, 5, 3, 0 }, - { 1, 2, 5, 4, 1 }, - { 1, 0, 3, 4, 1 }}; + { 0, 1, 4, 3, 0 }}; static int Penta_nbN [] = { 3, 3, 4, 4, 4 }; /* -// N7+----------+N6 +// N5+----------+N6 // /| /| // / | / | // / | / | -// N4+----------+N5 | +// N4+----------+N7 | // | | | | HEXAHEDRON // | | | | // | | | | -// | N3+------|---+N2 +// | N1+------|---+N2 // | / | / // | / | / // |/ |/ -// N0+----------+N1 +// N0+----------+N3 */ static int Hexa_F [6][5] = { // FORWARD { 0, 1, 2, 3, 0 }, // opposite faces are neighbouring, - { 4, 5, 6, 7, 4 }, // even face normal is internal, odd - external - { 1, 0, 4, 5, 1 }, // same index nodes nodes of opposite faces are linked + { 4, 5, 6, 7, 4 }, // odd face(1,3,5) normal is internal, even(0,2,4) - external + { 1, 0, 4, 5, 1 }, // same index nodes of opposite faces are linked { 2, 3, 7, 6, 2 }, { 0, 3, 7, 4, 0 }, - { 1, 2, 6, 5, 1 }}; -static int Hexa_R [6][5] = { // REVERSED - { 0, 3, 2, 1, 0 }, // opposite faces are neighbouring, - { 4, 7, 6, 5, 4 }, // even face normal is external, odd - internal - { 1, 5, 4, 0, 1 }, // same index nodes nodes of opposite faces are linked - { 2, 6, 7, 3, 2 }, - { 0, 4, 7, 3, 0 }, - { 1, 5, 6, 2, 1 }}; -static int Hexa_FE [6][5] = { // EXTERNAL - { 0, 3, 2, 1, 0 }, // opposite faces are neighbouring, - { 4, 5, 6, 7, 4 }, // all face normals are external, - { 0, 1, 5, 4, 0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1 - { 3, 7, 6, 2, 3 }, - { 1, 2, 6, 5, 1 }, - { 0, 4, 7, 3, 0 }}; -static int Hexa_RE [6][5] = { // REVERSED EXTERNAL - { 0, 1, 2, 3, 0 }, // opposite faces are neighbouring, - { 4, 7, 6, 5, 4 }, // all face normals are external, - { 0, 1, 5, 4, 0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1 + { 1, 2, 6, 5, 1 }}; +// static int Hexa_R [6][5] = { // REVERSED +// { 0, 3, 2, 1, 0 }, // opposite faces are neighbouring, +// { 4, 7, 6, 5, 4 }, // odd face(1,3,5) normal is external, even(0,2,4) - internal +// { 1, 5, 4, 0, 1 }, // same index nodes of opposite faces are linked +// { 2, 6, 7, 3, 2 }, +// { 0, 4, 7, 3, 0 }, +// { 1, 5, 6, 2, 1 }}; +static int Hexa_FE [6][5] = { // FORWARD -> EXTERNAL + { 0, 1, 2, 3, 0 } , // opposite faces are neighbouring, + { 4, 7, 6, 5, 4 }, // all face normals are external, + { 0, 4, 5, 1, 0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1 + { 3, 2, 6, 7, 3 }, + { 0, 3, 7, 4, 0 }, + { 1, 5, 6, 2, 1 }}; +static int Hexa_RE [6][5] = { // REVERSED -> EXTERNAL + { 0, 3, 2, 1, 0 }, // opposite faces are neighbouring, + { 4, 5, 6, 7, 4 }, // all face normals are external, + { 0, 1, 5, 4, 0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1 { 3, 7, 6, 2, 3 }, - { 1, 2, 6, 5, 1 }, - { 0, 4, 7, 3, 0 }}; + { 0, 4, 7, 3, 0 }, + { 1, 2, 6, 5, 1 }}; static int Hexa_nbN [] = { 4, 4, 4, 4, 4, 4 }; // ======================================================== @@ -166,7 +203,6 @@ SMDS_VolumeTool::SMDS_VolumeTool () myVolForward( true ), myNbFaces( 0 ), myVolumeNbNodes( 0 ), - myForwardFaces( false ), myExternalFaces( false ) { } @@ -176,8 +212,7 @@ SMDS_VolumeTool::SMDS_VolumeTool () //======================================================================= SMDS_VolumeTool::SMDS_VolumeTool (const SMDS_MeshElement* theVolume) - : myForwardFaces( false ), - myExternalFaces( false ) + : myExternalFaces( false ) { Set( theVolume ); } @@ -208,6 +243,7 @@ bool SMDS_VolumeTool::Set (const SMDS_MeshElement* theVolume) myVolumeNbNodes = theVolume->NbNodes(); switch ( myVolumeNbNodes ) { case 4: + case 5: case 6: case 8: { @@ -223,11 +259,13 @@ bool SMDS_VolumeTool::Set (const SMDS_MeshElement* theVolume) // nb nodes in each face if ( myVolumeNbNodes == 4 ) myFaceNbNodes = Tetra_nbN; + else if ( myVolumeNbNodes == 5 ) + myFaceNbNodes = Pyramid_nbN; else if ( myVolumeNbNodes == 6 ) myFaceNbNodes = Penta_nbN; else myFaceNbNodes = Hexa_nbN; - break; + // define volume orientation XYZ botNormal; GetFaceNormal( 0, botNormal.x, botNormal.y, botNormal.z ); @@ -236,9 +274,8 @@ bool SMDS_VolumeTool::Set (const SMDS_MeshElement* theVolume) XYZ upDir (topNode->X() - botNode->X(), topNode->Y() - botNode->Y(), topNode->Z() - botNode->Z() ); - bool diffDir = ( botNormal.Dot( upDir ) < 0 ); - myVolForward = ( myVolumeNbNodes == 6 ? diffDir : !diffDir ); - + myVolForward = ( botNormal.Dot( upDir ) < 0 ); + break; } default: myVolume = 0; } @@ -251,10 +288,10 @@ bool SMDS_VolumeTool::Set (const SMDS_MeshElement* theVolume) //purpose : Return nodes vector of an inverse volume //======================================================================= -#define SWAP_NODES(nodes,i1,i2) \ -{ \ +#define SWAP_NODES(nodes,i1,i2) \ +{ \ const SMDS_MeshNode* tmp = nodes[ i1 ]; \ - nodes[ i1 ] = nodes[ i2 ]; \ + nodes[ i1 ] = nodes[ i2 ]; \ nodes[ i2 ] = tmp; \ } void SMDS_VolumeTool::Inverse () @@ -269,6 +306,9 @@ void SMDS_VolumeTool::Inverse () case 4: SWAP_NODES( myVolumeNodes, 1, 2 ); break; + case 5: + SWAP_NODES( myVolumeNodes, 1, 3 ); + break; case 6: SWAP_NODES( myVolumeNodes, 1, 2 ); SWAP_NODES( myVolumeNodes, 4, 5 ); @@ -314,16 +354,6 @@ bool SMDS_VolumeTool::GetBaryCenter(double & X, double & Y, double & Z) const return true; } -//======================================================================= -//function : SetForwardOrientation -//purpose : Node order will be as for forward orientation -//======================================================================= - -void SMDS_VolumeTool::SetForwardOrientation () -{ - myForwardFaces = true; -} - //======================================================================= //function : SetExternalNormal //purpose : Node order will be so that faces normals are external @@ -332,6 +362,7 @@ void SMDS_VolumeTool::SetForwardOrientation () void SMDS_VolumeTool::SetExternalNormal () { myExternalFaces = true; + myCurFace = -1; } //======================================================================= @@ -381,15 +412,15 @@ const int* SMDS_VolumeTool::GetFaceNodesIndices( int faceIndex ) //purpose : Return a set of face nodes. //======================================================================= -bool SMDS_VolumeTool::GetFaceNodes (int faceIndex, - std::set& theFaceNodes ) +bool SMDS_VolumeTool::GetFaceNodes (int faceIndex, + set& theFaceNodes ) { if ( !setFace( faceIndex )) return false; theFaceNodes.clear(); int iNode, nbNode = myFaceNbNodes[ faceIndex ]; - for ( int iNode = 0; iNode < nbNode; iNode++ ) + for ( iNode = 0; iNode < nbNode; iNode++ ) theFaceNodes.insert( myFaceNodes[ iNode ]); return true; @@ -405,18 +436,18 @@ bool SMDS_VolumeTool::IsFaceExternal( int faceIndex ) if ( myExternalFaces || !myVolume ) return true; - bool reversed = ( !myForwardFaces && !myVolForward ); switch ( myVolumeNbNodes ) { case 4: - // only the bottom of a forward tetrahedron can be internal - return ( reversed || faceIndex != 0 ); + case 5: + // only the bottom of a reversed tetrahedron can be internal + return ( myVolForward || faceIndex != 0 ); case 6: // in a forward pentahedron, the top is internal, in a reversed one - bottom - return ( reversed ? faceIndex != 0 : faceIndex != 1 ); + return ( myVolForward ? faceIndex != 1 : faceIndex != 0 ); case 8: { - // in a forward hexahedron, odd face normal is external, else vice versa + // in a forward hexahedron, even face normal is external, odd - internal bool odd = faceIndex % 2; - return ( reversed ? !odd : odd ); + return ( myVolForward ? !odd : odd ); } default:; } @@ -540,6 +571,15 @@ bool SMDS_VolumeTool::IsLinked (const int theNode1Index, switch ( myVolumeNbNodes ) { case 4: return true; + case 5: + if ( maxInd == 4 ) + return true; + switch ( maxInd - minInd ) { + case 1: + case 3: return true; + default:; + } + break; case 6: switch ( maxInd - minInd ) { case 1: return minInd != 2; @@ -735,25 +775,25 @@ bool SMDS_VolumeTool::setFace( int faceIndex ) switch ( myVolumeNbNodes ) { case 4: if ( myExternalFaces ) - myFaceNodeIndices = myVolForward ? Tetra_R[ faceIndex ] : Tetra_F[ faceIndex ]; - else if ( myForwardFaces ) + myFaceNodeIndices = myVolForward ? Tetra_F[ faceIndex ] : Tetra_RE[ faceIndex ]; + else myFaceNodeIndices = myVolForward ? Tetra_F[ faceIndex ] : Tetra_R[ faceIndex ]; + break; + case 5: + if ( myExternalFaces ) + myFaceNodeIndices = myVolForward ? Pyramid_F[ faceIndex ] : Pyramid_RE[ faceIndex ]; else - myFaceNodeIndices = Tetra_F[ faceIndex ]; + myFaceNodeIndices = myVolForward ? Pyramid_F[ faceIndex ] : Pyramid_R[ faceIndex ]; break; case 6: if ( myExternalFaces ) myFaceNodeIndices = myVolForward ? Penta_FE[ faceIndex ] : Penta_RE[ faceIndex ]; - else if ( myForwardFaces ) - myFaceNodeIndices = myVolForward ? Penta_F[ faceIndex ] : Penta_R[ faceIndex ]; else - myFaceNodeIndices = Penta_F[ faceIndex ]; + myFaceNodeIndices = myVolForward ? Penta_F[ faceIndex ] : Penta_R[ faceIndex ]; break; case 8: if ( myExternalFaces ) myFaceNodeIndices = myVolForward ? Hexa_FE[ faceIndex ] : Hexa_RE[ faceIndex ]; - else if ( myForwardFaces ) - myFaceNodeIndices = myVolForward ? Hexa_F[ faceIndex ] : Hexa_R[ faceIndex ]; else myFaceNodeIndices = Hexa_F[ faceIndex ]; break; diff --git a/src/SMDS/SMDS_VolumeTool.hxx b/src/SMDS/SMDS_VolumeTool.hxx index 0c840a512..99e7dc176 100644 --- a/src/SMDS/SMDS_VolumeTool.hxx +++ b/src/SMDS/SMDS_VolumeTool.hxx @@ -62,7 +62,7 @@ class SMDS_VolumeTool bool IsForward() const { return myVolForward; } // Check volume orientation. can be changed by Inverse(). - // See node order of forward volumes at file bottom + // See node order of forward volumes at the file bottom void Inverse(); // Change nodes order as if the volume changes its orientation: @@ -101,12 +101,8 @@ class SMDS_VolumeTool // info on faces // ------------- - void SetForwardOrientation (); - // Node order in faces will be as for forward orientation - void SetExternalNormal (); // Node order in faces will be so that faces normals are external. - // It overrides SetForwardOrientation() int NbFaces() const { return myNbFaces; } // Return number of faces of the volume. In the following @@ -135,8 +131,7 @@ class SMDS_VolumeTool bool IsFaceExternal( int faceIndex ); // Check normal orientation of a face. - // SetForwardOrientation() and SetForwardOrientation() are taken - // into account. + // SetExternalNormal() is taken into account. bool IsFreeFace( int faceIndex ); // Check that all volumes built on the face nodes lays on one side @@ -169,7 +164,6 @@ class SMDS_VolumeTool int myVolumeNbNodes; const SMDS_MeshNode* myVolumeNodes[ 8 ]; - bool myForwardFaces; bool myExternalFaces; int* myFaceNodeIndices; int* myFaceNbNodes; @@ -191,13 +185,13 @@ class SMDS_VolumeTool // /|\ // / | \ // / | \ -// N0 +---|---+ N2 TETRAHEDRON +// N0 +---|---+ N1 TETRAHEDRON // \ | / // \ | / // \ | / // \|/ // + -// N1 +// N2 // + N4 // /|\ @@ -213,18 +207,18 @@ class SMDS_VolumeTool // |/ \| // N0 +---------+ N2 -// N7+----------+N6 +// N5+----------+N6 // /| /| // / | / | // / | / | -// N4+----------+N5 | +// N4+----------+N7 | // | | | | HEXAHEDRON // | | | | // | | | | -// | N3+------|---+N2 +// | N1+------|---+N2 // | / | / // | / | / // |/ |/ -// N0+----------+N1 +// N0+----------+N3 // */ diff --git a/src/SMESH/Makefile.in b/src/SMESH/Makefile.in index 81c62ca98..4189c8107 100644 --- a/src/SMESH/Makefile.in +++ b/src/SMESH/Makefile.in @@ -74,9 +74,9 @@ BIN = BIN_SRC = # additionnal information to compile and link file -CPPFLAGS+= $(OCC_INCLUDES) $(MED2_INCLUDES) $(HDF5_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome \ +CPPFLAGS+= $(OCC_INCLUDES) $(HDF5_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome \ -I${GEOM_ROOT_DIR}/include/salome $(BOOST_CPPFLAGS) -CXXFLAGS+= $(OCC_CXXFLAGS) $(MED2_INCLUDES) $(HDF5_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome \ +CXXFLAGS+= $(OCC_CXXFLAGS) $(HDF5_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome \ -I${GEOM_ROOT_DIR}/include/salome LDFLAGS+= -L${KERNEL_ROOT_DIR}/lib/salome -L${GEOM_ROOT_DIR}/lib/salome -lNMTTools -lSMESHDS -lMeshDriverDAT -lMeshDriverSTL -lMeshDriverMED -lMeshDriverUNV diff --git a/src/SMESH/SMESH_Block.cxx b/src/SMESH/SMESH_Block.cxx index 6550a81ea..016805fd3 100644 --- a/src/SMESH/SMESH_Block.cxx +++ b/src/SMESH/SMESH_Block.cxx @@ -40,6 +40,9 @@ #include #include +#include "SMDS_MeshNode.hxx" +#include "SMDS_MeshVolume.hxx" +#include "SMDS_VolumeTool.hxx" #include "utilities.h" #include @@ -56,6 +59,8 @@ using namespace std; double SMESH_Block::TEdge::GetU( const gp_XYZ& theParams ) const { double u = theParams.Coord( myCoordInd ); + if ( myC3d.IsNull() ) // if mesh block + return u; return ( 1 - u ) * myFirst + u * myLast; } @@ -66,12 +71,46 @@ double SMESH_Block::TEdge::GetU( const gp_XYZ& theParams ) const gp_XYZ SMESH_Block::TEdge::Point( const gp_XYZ& theParams ) const { - gp_XYZ p = myC3d->Value( GetU( theParams )).XYZ(); + double u = GetU( theParams ); + + if ( myC3d.IsNull() ) // if mesh block + return myNodes[0] * ( 1 - u ) + myNodes[1] * u; + + gp_XYZ p = myC3d->Value( u ).XYZ(); if ( myTrsf.Form() != gp_Identity ) myTrsf.Transforms( p ); return p; } +//======================================================================= +//function : SMESH_Block::TFace::GetCoefs +//purpose : return coefficients for addition of [0-3]-th edge and vertex +//======================================================================= + +void SMESH_Block::TFace::GetCoefs(int iE, + const gp_XYZ& theParams, + double& Ecoef, + double& Vcoef ) const +{ + double dU = theParams.Coord( GetUInd() ); + double dV = theParams.Coord( GetVInd() ); + switch ( iE ) { + case 0: + Ecoef = ( 1 - dV ); // u0 + Vcoef = ( 1 - dU ) * ( 1 - dV ); break; // 00 + case 1: + Ecoef = dV; // u1 + Vcoef = dU * ( 1 - dV ); break; // 10 + case 2: + Ecoef = ( 1 - dU ); // 0v + Vcoef = dU * dV ; break; // 11 + case 3: + Ecoef = dU ; // 1v + Vcoef = ( 1 - dU ) * dV ; break; // 01 + default: ASSERT(0); + } +} + //======================================================================= //function : SMESH_Block::TFace::GetUV //purpose : @@ -80,26 +119,10 @@ gp_XYZ SMESH_Block::TEdge::Point( const gp_XYZ& theParams ) const gp_XY SMESH_Block::TFace::GetUV( const gp_XYZ& theParams ) const { gp_XY uv(0.,0.); - double dU = theParams.Coord( GetUInd() ); - double dV = theParams.Coord( GetVInd() ); for ( int iE = 0; iE < 4; iE++ ) // loop on 4 edges { double Ecoef = 0, Vcoef = 0; - switch ( iE ) { - case 0: - Ecoef = ( 1 - dV ); // u0 - Vcoef = ( 1 - dU ) * ( 1 - dV ); break; // 00 - case 1: - Ecoef = dV; // u1 - Vcoef = dU * ( 1 - dV ); break; // 10 - case 2: - Ecoef = ( 1 - dU ); // 0v - Vcoef = dU * dV ; break; // 11 - case 3: - Ecoef = dU ; // 1v - Vcoef = ( 1 - dU ) * dV ; break; // 01 - default:; - } + GetCoefs( iE, theParams, Ecoef, Vcoef ); // edge addition double u = theParams.Coord( myCoordInd[ iE ] ); u = ( 1 - u ) * myFirst[ iE ] + u * myLast[ iE ]; @@ -117,10 +140,34 @@ gp_XY SMESH_Block::TFace::GetUV( const gp_XYZ& theParams ) const gp_XYZ SMESH_Block::TFace::Point( const gp_XYZ& theParams ) const { - gp_XY uv = GetUV( theParams ); - gp_XYZ p = myS->Value( uv.X(), uv.Y() ).XYZ(); - if ( myTrsf.Form() != gp_Identity ) - myTrsf.Transforms( p ); + gp_XYZ p(0.,0.,0.); + if ( myS.IsNull() ) // if mesh block + { + for ( int iE = 0; iE < 4; iE++ ) // loop on 4 edges + { + double Ecoef = 0, Vcoef = 0; + GetCoefs( iE, theParams, Ecoef, Vcoef ); + // edge addition + double u = theParams.Coord( myCoordInd[ iE ] ); + int i1 = 0, i2 = 1; + switch ( iE ) { + case 1: i1 = 3; i2 = 2; break; + case 2: i1 = 1; i2 = 2; break; + case 3: i1 = 0; i2 = 3; break; + } + p += Ecoef * ( myNodes[ i1 ] * ( 1 - u ) + myNodes[ i2 ] * u ); + // corner addition + p -= Vcoef * myNodes[ iE ]; + } + + } + else // shape block + { + gp_XY uv = GetUV( theParams ); + p = myS->Value( uv.X(), uv.Y() ).XYZ(); + if ( myTrsf.Form() != gp_Identity ) + myTrsf.Transforms( p ); + } return p; } @@ -274,7 +321,7 @@ Standard_Boolean SMESH_Block::Values(const math_Vector& theXYZ, return true; } - if ( theFxyz(1) < myValues[0] ) + if ( theFxyz(1) < myValues[0] ) // a better guess { // 3 partial derivatives gp_Vec drv[ 3 ]; @@ -620,6 +667,175 @@ static int getOrderedEdges (const TopoDS_Face& theFace, return aWireList.size(); } +//======================================================================= +//function : LoadMeshBlock +//purpose : prepare to work with theVolume +//======================================================================= + +#define gpXYZ(n) gp_XYZ(n->X(),n->Y(),n->Z()) + +bool SMESH_Block::LoadMeshBlock(const SMDS_MeshVolume* theVolume, + const int theNode000Index, + const int theNode001Index, + vector& theOrderedNodes) +{ + MESSAGE(" ::LoadMeshBlock()"); + + myNbIterations = 0; + mySumDist = 0; + myGridComputed = false; + + SMDS_VolumeTool vTool; + if (!vTool.Set( theVolume ) || vTool.NbNodes() != 8 || + !vTool.IsLinked( theNode000Index, theNode001Index )) { + MESSAGE(" Bad arguments "); + return false; + } + vTool.SetExternalNormal(); + // In terms of indices used for access to nodes and faces in SMDS_VolumeTool: + int V000, V100, V010, V110, V001, V101, V011, V111; // 8 vertices + int Fxy0, Fxy1; // bottom and top faces + // vertices of faces + vector vFxy0, vFxy1; + + V000 = theNode000Index; + V001 = theNode001Index; + + // get faces sharing V000 and V001 + list fV000, fV001; + int i, iF, iE, iN; + for ( iF = 0; iF < vTool.NbFaces(); ++iF ) { + const int* nid = vTool.GetFaceNodesIndices( iF ); + for ( iN = 0; iN < 4; ++iN ) + if ( nid[ iN ] == V000 ) { + fV000.push_back( iF ); + } else if ( nid[ iN ] == V001 ) { + fV001.push_back( iF ); + } + } + + // find the bottom (Fxy0), the top (Fxy1) faces + list::iterator fIt1, fIt2, Fxy0Pos; + for ( fIt1 = fV000.begin(); fIt1 != fV000.end(); fIt1++) { + fIt2 = std::find( fV001.begin(), fV001.end(), *fIt1 ); + if ( fIt2 != fV001.end() ) { // *fIt1 is in the both lists + fV001.erase( fIt2 ); // erase Fx0z or F0yz from fV001 + } else { // *fIt1 is in fV000 only + Fxy0Pos = fIt1; // points to Fxy0 + } + } + Fxy0 = *Fxy0Pos; + Fxy1 = fV001.front(); + const SMDS_MeshNode** nn = vTool.GetNodes(); + + // find bottom veritices, their order is that a face normal is external + vFxy0.resize(4); + const int* nid = vTool.GetFaceNodesIndices( Fxy0 ); + for ( i = 0; i < 4; ++i ) + if ( nid[ i ] == V000 ) + break; + for ( iN = 0; iN < 4; ++iN, ++i ) { + if ( i == 4 ) i = 0; + vFxy0[ iN ] = nid[ i ]; + } + // find top veritices, their order is that a face normal is external + vFxy1.resize(4); + nid = vTool.GetFaceNodesIndices( Fxy1 ); + for ( i = 0; i < 4; ++i ) + if ( nid[ i ] == V001 ) + break; + for ( iN = 0; iN < 4; ++iN, ++i ) { + if ( i == 4 ) i = 0; + vFxy1[ iN ] = nid[ i ]; + } + // find indices of the rest veritices + V100 = vFxy0[3]; + V010 = vFxy0[1]; + V110 = vFxy0[2]; + V101 = vFxy1[1]; + V011 = vFxy1[3]; + V111 = vFxy1[2]; + + // set points coordinates + myPnt[ ID_V000 - 1 ] = gpXYZ( nn[ V000 ] ); + myPnt[ ID_V100 - 1 ] = gpXYZ( nn[ V100 ] ); + myPnt[ ID_V010 - 1 ] = gpXYZ( nn[ V010 ] ); + myPnt[ ID_V110 - 1 ] = gpXYZ( nn[ V110 ] ); + myPnt[ ID_V001 - 1 ] = gpXYZ( nn[ V001 ] ); + myPnt[ ID_V101 - 1 ] = gpXYZ( nn[ V101 ] ); + myPnt[ ID_V011 - 1 ] = gpXYZ( nn[ V011 ] ); + myPnt[ ID_V111 - 1 ] = gpXYZ( nn[ V111 ] ); + + // fill theOrderedNodes + theOrderedNodes.resize( 8 ); + theOrderedNodes[ 0 ] = nn[ V000 ]; + theOrderedNodes[ 1 ] = nn[ V100 ]; + theOrderedNodes[ 2 ] = nn[ V010 ]; + theOrderedNodes[ 3 ] = nn[ V110 ]; + theOrderedNodes[ 4 ] = nn[ V001 ]; + theOrderedNodes[ 5 ] = nn[ V101 ]; + theOrderedNodes[ 6 ] = nn[ V011 ]; + theOrderedNodes[ 7 ] = nn[ V111 ]; + + // fill edges + myEdge[ ID_Ex00 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V000 - 1 ]; + myEdge[ ID_Ex00 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V100 - 1 ]; + + myEdge[ ID_Ex10 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V010 - 1 ]; + myEdge[ ID_Ex10 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V110 - 1 ]; + + myEdge[ ID_Ex01 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V001 - 1 ]; + myEdge[ ID_Ex01 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V101 - 1 ]; + + myEdge[ ID_Ex11 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V011 - 1 ]; + myEdge[ ID_Ex11 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V111 - 1 ]; + + myEdge[ ID_E0y0 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V000 - 1 ]; + myEdge[ ID_E0y0 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V010 - 1 ]; + + myEdge[ ID_E1y0 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V100 - 1 ]; + myEdge[ ID_E1y0 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V110 - 1 ]; + + myEdge[ ID_E0y1 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V001 - 1 ]; + myEdge[ ID_E0y1 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V011 - 1 ]; + + myEdge[ ID_E1y1 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V101 - 1 ]; + myEdge[ ID_E1y1 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V111 - 1 ]; + + myEdge[ ID_E00z - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V000 - 1 ]; + myEdge[ ID_E00z - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V001 - 1 ]; + + myEdge[ ID_E10z - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V100 - 1 ]; + myEdge[ ID_E10z - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V101 - 1 ]; + + myEdge[ ID_E01z - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V010 - 1 ]; + myEdge[ ID_E01z - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V011 - 1 ]; + + myEdge[ ID_E11z - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V110 - 1 ]; + myEdge[ ID_E11z - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V111 - 1 ]; + + for ( iE = ID_Ex00; iE <= ID_E11z; ++iE ) + myEdge[ iE - ID_Ex00 ].myCoordInd = GetCoordIndOnEdge( iE ); + + // fill faces corners + for ( iF = ID_Fxy0; iF < ID_Shell; ++iF ) + { + TFace& tFace = myFace[ iF - ID_Fxy0 ]; + vector< int > edgeIdVec(4, -1); + GetFaceEdgesIDs( iF, edgeIdVec ); + tFace.myNodes[ 0 ] = myEdge[ edgeIdVec [ 0 ] - ID_Ex00 ].myNodes[ 1 ]; + tFace.myNodes[ 1 ] = myEdge[ edgeIdVec [ 0 ] - ID_Ex00 ].myNodes[ 0 ]; + tFace.myNodes[ 2 ] = myEdge[ edgeIdVec [ 1 ] - ID_Ex00 ].myNodes[ 0 ]; + tFace.myNodes[ 3 ] = myEdge[ edgeIdVec [ 1 ] - ID_Ex00 ].myNodes[ 1 ]; + tFace.myCoordInd[ 0 ] = GetCoordIndOnEdge( edgeIdVec[ 0 ] ); + tFace.myCoordInd[ 1 ] = GetCoordIndOnEdge( edgeIdVec[ 1 ] ); + tFace.myCoordInd[ 2 ] = GetCoordIndOnEdge( edgeIdVec[ 2 ] ); + tFace.myCoordInd[ 3 ] = GetCoordIndOnEdge( edgeIdVec[ 3 ] ); + } + + return true; +} + //======================================================================= //function : LoadBlockShapes //purpose : add sub-shapes of theBlock to theShapeIDMap so that they get @@ -629,7 +845,6 @@ static int getOrderedEdges (const TopoDS_Face& theFace, bool SMESH_Block::LoadBlockShapes(const TopoDS_Shell& theShell, const TopoDS_Vertex& theVertex000, const TopoDS_Vertex& theVertex001, -// TopTools_IndexedMapOfShape& theShapeIDMap TopTools_IndexedMapOfOrientedShape& theShapeIDMap ) { MESSAGE(" ::LoadBlockShapes()"); @@ -639,7 +854,7 @@ bool SMESH_Block::LoadBlockShapes(const TopoDS_Shell& theShell, mySumDist = 0; myGridComputed = false; - // 6 vertices + // 8 vertices TopoDS_Shape V000, V100, V010, V110, V001, V101, V011, V111; // 12 edges TopoDS_Shape Ex00, Ex10, Ex01, Ex11; @@ -976,6 +1191,7 @@ bool SMESH_Block::LoadBlockShapes(const TopoDS_Shell& theShell, void SMESH_Block::GetFaceEdgesIDs (const int faceID, vector< int >& edgeVec ) { + edgeVec.resize( 4 ); switch ( faceID ) { case ID_Fxy0: edgeVec[ 0 ] = ID_Ex00; @@ -1017,3 +1233,69 @@ void SMESH_Block::GetFaceEdgesIDs (const int faceID, vector< int >& edgeVec ) MESSAGE(" GetFaceEdgesIDs(), wrong face ID: " << faceID ); } } + +//======================================================================= +//function : GetEdgeVertexIDs +//purpose : return vertex IDs of an edge +//======================================================================= + +void SMESH_Block::GetEdgeVertexIDs (const int edgeID, vector< int >& vertexVec ) +{ + vertexVec.resize( 2 ); + switch ( edgeID ) { + + case ID_Ex00: + vertexVec[ 0 ] = ID_V000; + vertexVec[ 1 ] = ID_V100; + break; + case ID_Ex10: + vertexVec[ 0 ] = ID_V010; + vertexVec[ 1 ] = ID_V110; + break; + case ID_Ex01: + vertexVec[ 0 ] = ID_V001; + vertexVec[ 1 ] = ID_V101; + break; + case ID_Ex11: + vertexVec[ 0 ] = ID_V011; + vertexVec[ 1 ] = ID_V111; + break; + + case ID_E0y0: + vertexVec[ 0 ] = ID_V000; + vertexVec[ 1 ] = ID_V010; + break; + case ID_E1y0: + vertexVec[ 0 ] = ID_V100; + vertexVec[ 1 ] = ID_V110; + break; + case ID_E0y1: + vertexVec[ 0 ] = ID_V001; + vertexVec[ 1 ] = ID_V011; + break; + case ID_E1y1: + vertexVec[ 0 ] = ID_V101; + vertexVec[ 1 ] = ID_V111; + break; + + case ID_E00z: + vertexVec[ 0 ] = ID_V000; + vertexVec[ 1 ] = ID_V001; + break; + case ID_E10z: + vertexVec[ 0 ] = ID_V100; + vertexVec[ 1 ] = ID_V101; + break; + case ID_E01z: + vertexVec[ 0 ] = ID_V010; + vertexVec[ 1 ] = ID_V011; + break; + case ID_E11z: + vertexVec[ 0 ] = ID_V110; + vertexVec[ 1 ] = ID_V111; + break; + default: + MESSAGE(" GetEdgeVertexIDs(), wrong edge ID: " << edgeID ); + } +} + diff --git a/src/SMESH/SMESH_Block.hxx b/src/SMESH/SMESH_Block.hxx index d937aeddd..7ab38891a 100644 --- a/src/SMESH/SMESH_Block.hxx +++ b/src/SMESH/SMESH_Block.hxx @@ -44,6 +44,9 @@ #include #include +class SMDS_MeshVolume; +class SMDS_MeshNode; + // ========================================================= // class calculating coordinates of 3D points by normalized // parameters inside the block and vice versa @@ -85,6 +88,13 @@ class SMESH_Block: public math_FunctionSetWithDerivatives // add sub-shapes of theBlock to theShapeIDMap so that they get // IDs acoording to enum TShapeID + bool LoadMeshBlock(const SMDS_MeshVolume* theVolume, + const int theNode000Index, + const int theNode001Index, + vector& theOrderedNodes); + // prepare to work with theVolume and + // return nodes in the order of TShapeID enum + static int GetShapeIDByParams ( const gp_XYZ& theParams ); // define an id of the block sub-shape by point parameters @@ -117,6 +127,9 @@ class SMESH_Block: public math_FunctionSetWithDerivatives static void GetFaceEdgesIDs (const int faceID, vector< int >& edgeVec ); // return edges IDs of a face in the order u0, u1, 0v, 1v + static void GetEdgeVertexIDs (const int edgeID, vector< int >& vertexVec ); + // return vertex IDs of an edge + static int GetCoordIndOnEdge (const int theEdgeID) { return (theEdgeID < ID_E0y0) ? 1 : (theEdgeID < ID_E00z) ? 2 : 3; } // return an index of a coordinate which varies along the edge @@ -161,6 +174,8 @@ class SMESH_Block: public math_FunctionSetWithDerivatives gp_Trsf myTrsf; double GetU( const gp_XYZ& theParams ) const; gp_XYZ Point( const gp_XYZ& theParams ) const; + // if mesh volume + gp_XYZ myNodes[2]; }; struct TFace { @@ -178,10 +193,13 @@ class SMESH_Block: public math_FunctionSetWithDerivatives gp_XYZ Point( const gp_XYZ& theParams ) const; int GetUInd() const { return myCoordInd[ 0 ]; } int GetVInd() const { return myCoordInd[ 2 ]; } + void GetCoefs( int i, const gp_XYZ& theParams, double& eCoef, double& vCoef ) const; + // if mesh volume + gp_XYZ myNodes[4]; }; TopoDS_Shell myShell; - // geometry: + // geometry in the order as in TShapeID: // 8 vertices gp_XYZ myPnt[ 8 ]; // 12 edges diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 0c05113cf..a778699e1 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -631,11 +631,15 @@ throw(SALOME_Exception) */ //============================================================================= -void SMESH_Mesh::ExportMED(const char *file, const char* theMeshName, bool theAutoGroups) throw(SALOME_Exception) +void SMESH_Mesh::ExportMED(const char *file, + const char* theMeshName, + bool theAutoGroups, + int theVersion) + throw(SALOME_Exception) { Unexpect aCatch(SalomeException); DriverMED_W_SMESHDS_Mesh myWriter; - myWriter.SetFile ( file ); + myWriter.SetFile ( file, MED::EVersion(theVersion) ); myWriter.SetMesh ( _myMeshDS ); if ( !theMeshName ) myWriter.SetMeshId ( _idDoc ); diff --git a/src/SMESH/SMESH_Mesh.hxx b/src/SMESH/SMESH_Mesh.hxx index 51f085364..0ddd8398b 100644 --- a/src/SMESH/SMESH_Mesh.hxx +++ b/src/SMESH/SMESH_Mesh.hxx @@ -136,8 +136,13 @@ public: // return list of ancestors of theSubShape in the order // that lower dimention shapes come first. + void ExportMED(const char *file, + const char* theMeshName = NULL, + bool theAutoGroups = true, + int theVersion = 0) + throw(SALOME_Exception); + void ExportDAT(const char *file) throw(SALOME_Exception); - void ExportMED(const char *file, const char* theMeshName = NULL, bool theAutoGroups = true) throw(SALOME_Exception); void ExportUNV(const char *file) throw(SALOME_Exception); void ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception); diff --git a/src/SMESH/SMESH_MeshEditor.cxx b/src/SMESH/SMESH_MeshEditor.cxx index 71a4d3c11..dc39a8e4d 100644 --- a/src/SMESH/SMESH_MeshEditor.cxx +++ b/src/SMESH/SMESH_MeshEditor.cxx @@ -28,31 +28,45 @@ #include "SMESH_MeshEditor.hxx" +#include "SMESH_ControlsDef.hxx" + #include "SMDS_FaceOfNodes.hxx" #include "SMDS_VolumeTool.hxx" #include "SMESHDS_Group.hxx" #include "SMESHDS_Mesh.hxx" #include "SMESH_subMesh.hxx" +#include "SMESH_ControlsDef.hxx" #include "utilities.h" -#include #include #include +#include #include #include #include #include +#include #include #include +#include +#include +#include + #include +#include "utilities.h" + using namespace std; +using namespace SMESH::Controls; -typedef map TNodeNodeMap; -typedef map > TNodeOfNodeListMap; -typedef map > TElemOfNodeListMap; +typedef map TNodeNodeMap; +typedef map > TElemOfNodeListMap; +typedef map > TElemOfElemListMap; +typedef map > TNodeOfNodeListMap; +typedef TNodeOfNodeListMap::iterator TNodeOfNodeListMapItr; +typedef map > TElemOfVecOfNnlmiMap; //======================================================================= //function : SMESH_MeshEditor @@ -493,7 +507,7 @@ bool SMESH_MeshEditor::Reorient (const SMDS_MeshElement * theFace) static double getBadRate (const SMDS_MeshElement* theElem, SMESH::Controls::NumericalFunctorPtr& theCrit) { - TColgp_SequenceOfXYZ P; + SMESH::Controls::TSequenceOfXYZ P; if ( !theElem || !theCrit->GetPoints( theElem, P )) return 1e100; return theCrit->GetBadRate( theCrit->GetValue( P ), theElem->NbNodes() ); @@ -568,13 +582,13 @@ bool SMESH_MeshEditor::QuadToTri (set & theElems, } //======================================================================= -//function : addToSameGroups +//function : AddToSameGroups //purpose : add elemToAdd to the groups the elemInGroups belongs to //======================================================================= -static void addToSameGroups (const SMDS_MeshElement* elemToAdd, - const SMDS_MeshElement* elemInGroups, - SMESHDS_Mesh * aMesh) +void SMESH_MeshEditor::AddToSameGroups (const SMDS_MeshElement* elemToAdd, + const SMDS_MeshElement* elemInGroups, + SMESHDS_Mesh * aMesh) { const set& groups = aMesh->GetGroups(); set::const_iterator grIt = groups.begin(); @@ -630,7 +644,7 @@ bool SMESH_MeshEditor::QuadToTri (std::set & theElems, if ( aShapeId ) aMesh->SetMeshElementOnShape( newElem, aShapeId ); - addToSameGroups( newElem, elem, aMesh ); + AddToSameGroups( newElem, elem, aMesh ); } return true; @@ -649,7 +663,7 @@ double getAngle(const SMDS_MeshElement * tr1, double angle = 2*PI; // bad angle // get normals - TColgp_SequenceOfXYZ P1, P2; + SMESH::Controls::TSequenceOfXYZ P1, P2; if ( !SMESH::Controls::NumericalFunctor::GetPoints( tr1, P1 ) || !SMESH::Controls::NumericalFunctor::GetPoints( tr2, P2 )) return angle; @@ -1315,13 +1329,13 @@ void centroidalSmooth(SMESHDS_Mesh * theMesh, nbElems++; gp_XYZ elemCenter(0.,0.,0.); - TColgp_SequenceOfXYZ aNodePoints; + SMESH::Controls::TSequenceOfXYZ aNodePoints; SMDS_ElemIteratorPtr itN = elem->nodesIterator(); while ( itN->more() ) { const SMDS_MeshNode* aNode = static_cast( itN->next() ); gp_XYZ aP( aNode->X(), aNode->Y(), aNode->Z() ); - aNodePoints.Append( aP ); + aNodePoints.push_back( aP ); elemCenter += aP; } double elemArea = anAreaFunc.GetValue( aNodePoints ); @@ -1453,7 +1467,7 @@ void SMESH_MeshEditor::Smooth (set & theElems, const SMDS_MeshElement* elem = (*itElem); if ( !elem || elem->GetType() != SMDSAbs_Face ) continue; - TColgp_SequenceOfXYZ aPoints; + SMESH::Controls::TSequenceOfXYZ aPoints; if ( aQualityFunc.GetPoints( elem, aPoints )) { double aValue = aQualityFunc.GetValue( aPoints ); if ( aValue > maxRatio ) @@ -1472,7 +1486,9 @@ void SMESH_MeshEditor::Smooth (set & theElems, //======================================================================= //function : isReverse -//purpose : +//purpose : Return true if normal of prevNodes is not co-directied with +// gp_Vec(prevNodes[iNotSame],nextNodes[iNotSame]). +// iNotSame is where prevNodes and nextNodes are different //======================================================================= static bool isReverse(const SMDS_MeshNode* prevNodes[], @@ -1500,42 +1516,39 @@ static bool isReverse(const SMDS_MeshNode* prevNodes[], //======================================================================= //function : sweepElement -//purpose : +//purpose : //======================================================================= -static void sweepElement(SMESHDS_Mesh* aMesh, - const SMDS_MeshElement* elem, - const TNodeOfNodeListMap& mapNewNodes ) +static void sweepElement(SMESHDS_Mesh* aMesh, + const SMDS_MeshElement* elem, + const vector & newNodesItVec, + list& newElems) { // Loop on elem nodes: // find new nodes and detect same nodes indices - list::const_iterator itNN[ 4 ]; - const SMDS_MeshNode* prevNod[ 4 ], *nextNod[ 4 ]; - int nbSame = 0, iNotSameNode = 0, iSameNode = 0; - - TNodeOfNodeListMap::const_iterator mapIt; - int iNode = 0; - SMDS_ElemIteratorPtr itN = elem->nodesIterator(); - while ( itN->more() ) + int nbNodes = elem->NbNodes(); + list::const_iterator itNN[ nbNodes ]; + const SMDS_MeshNode* prevNod[ nbNodes ], *nextNod[ nbNodes ]; + int iNode, nbSame = 0, iNotSameNode = 0, iSameNode = 0; + + for ( iNode = 0; iNode < nbNodes; iNode++ ) { - const SMDS_MeshNode* node = - static_cast( itN->next() ); - mapIt = mapNewNodes.find( node ); - if ( mapIt == mapNewNodes.end() ) - return; // not duplicated node + TNodeOfNodeListMapItr nnIt = newNodesItVec[ iNode ]; + const SMDS_MeshNode* node = nnIt->first; + const list< const SMDS_MeshNode* > & listNewNodes = nnIt->second; + if ( listNewNodes.empty() ) + return; - itNN[ iNode ] = (*mapIt).second.begin(); + itNN[ iNode ] = listNewNodes.begin(); prevNod[ iNode ] = node; - nextNod[ iNode ] = (*mapIt).second.front(); + nextNod[ iNode ] = listNewNodes.front(); if ( prevNod[ iNode ] != nextNod [ iNode ]) iNotSameNode = iNode; else { iSameNode = iNode; nbSame++; } - iNode++; } - int nbNodes = iNode; if ( nbSame == nbNodes || nbSame > 2) { MESSAGE( " Too many same nodes of element " << elem->GetID() ); return; @@ -1550,8 +1563,8 @@ static void sweepElement(SMESHDS_Mesh* aMesh, // check element orientation int i0 = 0, i2 = 2; - if ( nbNodes > 2 && isReverse( prevNod, nextNod, nbNodes, iNotSameNode )) { -// MESSAGE("Reversed elem " << elem->GetID() ); + if ( nbNodes > 2 && !isReverse( prevNod, nextNod, nbNodes, iNotSameNode )) { + //MESSAGE("Reversed elem " << elem ); i0 = 2; i2 = 0; if ( nbSame > 0 ) { @@ -1562,7 +1575,7 @@ static void sweepElement(SMESHDS_Mesh* aMesh, } // make new elements - int iStep, nbSteps = (*mapIt).second.size(); + int iStep, nbSteps = newNodesItVec[ 0 ]->second.size(); for (iStep = 0; iStep < nbSteps; iStep++ ) { // get next nodes @@ -1570,69 +1583,76 @@ static void sweepElement(SMESHDS_Mesh* aMesh, nextNod[ iNode ] = *itNN[ iNode ]; itNN[ iNode ]++; } + SMDS_MeshElement* aNewElem = 0; switch ( nbNodes ) { + case 1: { // NODE + if ( nbSame == 0 ) + aNewElem = aMesh->AddEdge( prevNod[ 0 ], nextNod[ 0 ] ); + break; + } case 2: { // EDGE if ( nbSame == 0 ) - aMesh->AddFace( prevNod[ 0 ], prevNod[ 1 ], nextNod[ 1 ], nextNod[ 0 ] ); + aNewElem = aMesh->AddFace(prevNod[ 0 ], prevNod[ 1 ], + nextNod[ 1 ], nextNod[ 0 ] ); else - aMesh->AddFace( prevNod[ 0 ], prevNod[ 1 ], nextNod[ iNotSameNode ] ); + aNewElem = aMesh->AddFace(prevNod[ 0 ], prevNod[ 1 ], + nextNod[ iNotSameNode ] ); break; } case 3: { // TRIANGLE - if ( nbSame == 0 ) // --- 1 pentahedron - { - aMesh->AddVolume (prevNod[ i2 ], prevNod[ 1 ], prevNod[ i0 ], - nextNod[ i2 ], nextNod[ 1 ], nextNod[ i0 ] ); - } - else if ( nbSame == 1 ) // --- 2 tetrahedrons - { - aMesh->AddVolume (prevNod[ i0 ], prevNod[ 1 ], prevNod[ i2 ], - nextNod[ iBeforeSame ]); - aMesh->AddVolume (nextNod[ i2 ], nextNod[ 1 ], nextNod[ i0 ], - prevNod[ iAfterSame ]); - } - else // 2 same nodes: --- 1 tetrahedron - { - aMesh->AddVolume (prevNod[ i0 ], prevNod[ 1 ], prevNod[ i2 ], - nextNod[ iNotSameNode ]); - } + if ( nbSame == 0 ) // --- pentahedron + aNewElem = aMesh->AddVolume (prevNod[ i0 ], prevNod[ 1 ], prevNod[ i2 ], + nextNod[ i0 ], nextNod[ 1 ], nextNod[ i2 ] ); + + else if ( nbSame == 1 ) // --- pyramid + aNewElem = aMesh->AddVolume (prevNod[ iAfterSame ], prevNod[ iBeforeSame ], + nextNod[ iBeforeSame ], nextNod[ iAfterSame ], + nextNod[ iSameNode ]); + + else // 2 same nodes: --- tetrahedron + aNewElem = aMesh->AddVolume (prevNod[ i0 ], prevNod[ 1 ], prevNod[ i2 ], + nextNod[ iNotSameNode ]); break; } case 4: { // QUADRANGLE - if ( nbSame == 0 ) // --- 1 hexahedron - { - aMesh->AddVolume (prevNod[ i0 ], prevNod[ 1 ], prevNod[ i2 ], prevNod[ 3 ], - nextNod[ i0 ], nextNod[ 1 ], nextNod[ i2 ], nextNod[ 3 ]); - } - else if ( nbSame == 1 ) // --- 2 tetrahedrons + 1 pentahedron + if ( nbSame == 0 ) // --- hexahedron + aNewElem = aMesh->AddVolume (prevNod[ i0 ], prevNod[ 1 ], prevNod[ i2 ], prevNod[ 3 ], + nextNod[ i0 ], nextNod[ 1 ], nextNod[ i2 ], nextNod[ 3 ]); + + else if ( nbSame == 1 ) // --- pyramid + pentahedron { - aMesh->AddVolume (prevNod[ iBeforeSame ], prevNod[ iSameNode ], - prevNod[ iAfterSame ], nextNod[ iBeforeSame ]); - aMesh->AddVolume (nextNod[ iAfterSame ], nextNod[ iSameNode ], - nextNod[ iBeforeSame ], prevNod[ iAfterSame ]); - aMesh->AddVolume (prevNod[ iBeforeSame ], prevNod[ iOpposSame ], prevNod[ iAfterSame ], - nextNod[ iBeforeSame ], nextNod[ iOpposSame ], nextNod[ iAfterSame ] ); + aNewElem = aMesh->AddVolume (prevNod[ iAfterSame ], prevNod[ iBeforeSame ], + nextNod[ iBeforeSame ], nextNod[ iAfterSame ], + nextNod[ iSameNode ]); + newElems.push_back( aNewElem ); + aNewElem = aMesh->AddVolume (prevNod[ iBeforeSame ], prevNod[ iOpposSame ], + prevNod[ iAfterSame ], nextNod[ iBeforeSame ], + nextNod[ iOpposSame ], nextNod[ iAfterSame ] ); } - else if ( nbSame == 2 ) // 1 pentahedron + else if ( nbSame == 2 ) // pentahedron { if ( prevNod[ iBeforeSame ] == nextNod[ iBeforeSame ] ) // iBeforeSame is same too - aMesh->AddVolume (prevNod[ iOpposSame ], prevNod[ iBeforeSame ], nextNod[ iOpposSame ], - prevNod[ iAfterSame ], prevNod[ iSameNode ], nextNod[ iAfterSame ]); + aNewElem = aMesh->AddVolume (prevNod[ iOpposSame ], prevNod[ iBeforeSame ], + nextNod[ iOpposSame ], prevNod[ iAfterSame ], + prevNod[ iSameNode ], nextNod[ iAfterSame ]); else // iAfterSame is same too - aMesh->AddVolume (prevNod[ iBeforeSame ], prevNod[ iSameNode ], nextNod[ iBeforeSame ], - prevNod[ iOpposSame ], prevNod[ iAfterSame ], nextNod[ iOpposSame ]); + aNewElem = aMesh->AddVolume (prevNod[ iBeforeSame ], prevNod[ iSameNode ], + nextNod[ iBeforeSame ], prevNod[ iOpposSame ], + prevNod[ iAfterSame ], nextNod[ iOpposSame ]); } break; } default: return; } + if ( aNewElem ) + newElems.push_back( aNewElem ); // set new prev nodes for ( iNode = 0; iNode < nbNodes; iNode++ ) @@ -1641,6 +1661,162 @@ static void sweepElement(SMESHDS_Mesh* aMesh, } // for steps } +//======================================================================= +//function : makeWalls +//purpose : create 1D and 2D elements around swept elements +//======================================================================= + +static void makeWalls (SMESHDS_Mesh* aMesh, + TNodeOfNodeListMap & mapNewNodes, + TElemOfElemListMap & newElemsMap, + TElemOfVecOfNnlmiMap & elemNewNodesMap, + set& elemSet) +{ + ASSERT( newElemsMap.size() == elemNewNodesMap.size() ); + + // Find nodes belonging to only one initial element - sweep them to get edges. + + TNodeOfNodeListMapItr nList = mapNewNodes.begin(); + for ( ; nList != mapNewNodes.end(); nList++ ) + { + const SMDS_MeshNode* node = + static_cast( nList->first ); + SMDS_ElemIteratorPtr eIt = node->GetInverseElementIterator(); + int nbInitElems = 0; + while ( eIt->more() && nbInitElems < 2 ) + if ( elemSet.find( eIt->next() ) != elemSet.end() ) + nbInitElems++; + if ( nbInitElems < 2 ) { + vector newNodesItVec( 1, nList ); + list newEdges; + sweepElement( aMesh, node, newNodesItVec, newEdges ); + } + } + + // Make a ceiling for each element ie an equal element of last new nodes. + // Find free links of faces - make edges and sweep them into faces. + + TElemOfElemListMap::iterator itElem = newElemsMap.begin(); + TElemOfVecOfNnlmiMap::iterator itElemNodes = elemNewNodesMap.begin(); + for ( ; itElem != newElemsMap.end(); itElem++, itElemNodes++ ) + { + const SMDS_MeshElement* elem = itElem->first; + vector& vecNewNodes = itElemNodes->second; + + if ( elem->GetType() == SMDSAbs_Edge ) + { + // create a ceiling edge + aMesh->AddEdge(vecNewNodes[ 0 ]->second.back(), + vecNewNodes[ 1 ]->second.back() ); + } + if ( elem->GetType() != SMDSAbs_Face ) + continue; + + bool hasFreeLinks = false; + + set avoidSet; + avoidSet.insert( elem ); + + // loop on a face nodes + set aFaceLastNodes; + int iNode, nbNodes = vecNewNodes.size(); + for ( iNode = 0; iNode < nbNodes; iNode++ ) + { + aFaceLastNodes.insert( vecNewNodes[ iNode ]->second.back() ); + // look for free links of a face + int iNext = ( iNode + 1 == nbNodes ) ? 0 : iNode + 1; + const SMDS_MeshNode* n1 = vecNewNodes[ iNode ]->first; + const SMDS_MeshNode* n2 = vecNewNodes[ iNext ]->first; + // check if a link is free + if ( ! SMESH_MeshEditor::FindFaceInSet ( n1, n2, elemSet, avoidSet )) + { + hasFreeLinks = true; + // make an edge and a ceiling for a new edge + if ( !aMesh->FindEdge( n1, n2 )) + aMesh->AddEdge( n1, n2 ); + n1 = vecNewNodes[ iNode ]->second.back(); + n2 = vecNewNodes[ iNext ]->second.back(); + if ( !aMesh->FindEdge( n1, n2 )) + aMesh->AddEdge( n1, n2 ); + } + } + // sweep free links into faces + + if ( hasFreeLinks ) + { + list & newVolumes = itElem->second; + int iStep, nbSteps = vecNewNodes[0]->second.size(); + int iVol, volNb, nbVolumesByStep = newVolumes.size() / nbSteps; + + set initNodeSet, faceNodeSet; + for ( iNode = 0; iNode < nbNodes; iNode++ ) + initNodeSet.insert( vecNewNodes[ iNode ]->first ); + + for ( volNb = 0; volNb < nbVolumesByStep; volNb++ ) + { + list::iterator v = newVolumes.begin(); + iVol = 0; + while ( iVol++ < volNb ) v++; + // find indices of free faces of a volume + list< int > fInd; + SMDS_VolumeTool vTool( *v ); + int iF, nbF = vTool.NbFaces(); + for ( iF = 0; iF < nbF; iF ++ ) + if (vTool.IsFreeFace( iF ) && + vTool.GetFaceNodes( iF, faceNodeSet ) && + initNodeSet != faceNodeSet) // except an initial face + fInd.push_back( iF ); + if ( fInd.empty() ) + continue; + + // create faces for all steps + for ( iStep = 0; iStep < nbSteps; iStep++ ) + { + vTool.Set( *v ); + vTool.SetExternalNormal(); + list< int >::iterator ind = fInd.begin(); + for ( ; ind != fInd.end(); ind++ ) + { + const SMDS_MeshNode** nodes = vTool.GetFaceNodes( *ind ); + switch ( vTool.NbFaceNodes( *ind ) ) { + case 3: + aMesh->AddFace( nodes[ 0 ], nodes[ 1 ], nodes[ 2 ] ); break; + case 4: + aMesh->AddFace( nodes[ 0 ], nodes[ 1 ], nodes[ 2 ], nodes[ 3 ] ); break; + } + } + // go to the next volume + iVol = 0; + while ( iVol++ < nbVolumesByStep ) v++; + } + } + } // sweep free links into faces + + // make a ceiling face with a normal external to a volume + + SMDS_VolumeTool lastVol( itElem->second.back() ); + int iF = lastVol.GetFaceIndex( aFaceLastNodes ); + if ( iF >= 0 ) + { + lastVol.SetExternalNormal(); + const SMDS_MeshNode** nodes = lastVol.GetFaceNodes( iF ); + switch ( lastVol.NbFaceNodes( iF ) ) { + case 3: + if (!hasFreeLinks || + !aMesh->FindFace( nodes[ 0 ], nodes[ 1 ], nodes[ 2 ])) + aMesh->AddFace( nodes[ 0 ], nodes[ 1 ], nodes[ 2 ] ); + break; + case 4: + if (!hasFreeLinks || + !aMesh->FindFace( nodes[ 0 ], nodes[ 1 ], nodes[ 2 ], nodes[ 3 ])) + aMesh->AddFace( nodes[ 0 ], nodes[ 1 ], nodes[ 2 ], nodes[ 3 ] ); + break; + } + } + + } // loop on swept elements +} + //======================================================================= //function : RotationSweep //purpose : @@ -1652,6 +1828,7 @@ void SMESH_MeshEditor::RotationSweep(set & theElems, const int theNbSteps, const double theTol) { + MESSAGE( "RotationSweep()"); gp_Trsf aTrsf; aTrsf.SetRotation( theAxis, theAngle ); @@ -1661,17 +1838,18 @@ void SMESH_MeshEditor::RotationSweep(set & theElems, SMESHDS_Mesh* aMesh = GetMeshDS(); TNodeOfNodeListMap mapNewNodes; + TElemOfVecOfNnlmiMap mapElemNewNodes; + TElemOfElemListMap newElemsMap; // loop on theElems set< const SMDS_MeshElement* >::iterator itElem; for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ ) { - // check element type const SMDS_MeshElement* elem = (*itElem); - if ( !elem || - (elem->GetType() != SMDSAbs_Face && - elem->GetType() != SMDSAbs_Edge )) + if ( !elem ) continue; + vector & newNodesItVec = mapElemNewNodes[ elem ]; + newNodesItVec.reserve( elem->NbNodes() ); // loop on elem nodes SMDS_ElemIteratorPtr itN = elem->nodesIterator(); @@ -1680,28 +1858,34 @@ void SMESH_MeshEditor::RotationSweep(set & theElems, // check if a node has been already sweeped const SMDS_MeshNode* node = static_cast( itN->next() ); - if (mapNewNodes.find( node ) != mapNewNodes.end() ) - continue; - - list& listNewNodes = mapNewNodes[ node ]; - - // make new nodes - gp_XYZ aXYZ( node->X(), node->Y(), node->Z() ); - double coord[3]; - aXYZ.Coord( coord[0], coord[1], coord[2] ); - bool isOnAxis = ( aLine.SquareDistance( aXYZ ) <= aSqTol ); - const SMDS_MeshNode * newNode = node; - for ( int i = 0; i < theNbSteps; i++ ) { - if ( !isOnAxis ) { - aTrsf.Transforms( coord[0], coord[1], coord[2] ); - newNode = aMesh->AddNode( coord[0], coord[1], coord[2] ); + TNodeOfNodeListMapItr nIt = mapNewNodes.find( node ); + if ( nIt == mapNewNodes.end() ) + { + nIt = mapNewNodes.insert( make_pair( node, list() )).first; + list& listNewNodes = nIt->second; + + // make new nodes + gp_XYZ aXYZ( node->X(), node->Y(), node->Z() ); + double coord[3]; + aXYZ.Coord( coord[0], coord[1], coord[2] ); + bool isOnAxis = ( aLine.SquareDistance( aXYZ ) <= aSqTol ); + const SMDS_MeshNode * newNode = node; + for ( int i = 0; i < theNbSteps; i++ ) { + if ( !isOnAxis ) { + aTrsf.Transforms( coord[0], coord[1], coord[2] ); + newNode = aMesh->AddNode( coord[0], coord[1], coord[2] ); + } + listNewNodes.push_back( newNode ); } - listNewNodes.push_back( newNode ); } + newNodesItVec.push_back( nIt ); } // make new elements - sweepElement( aMesh, elem, mapNewNodes ); + sweepElement( aMesh, elem, newNodesItVec, newElemsMap[elem] ); } + + makeWalls( aMesh, mapNewNodes, newElemsMap, mapElemNewNodes, theElems ); + } //======================================================================= //function : ExtrusionSweep @@ -1718,6 +1902,8 @@ void SMESH_MeshEditor::ExtrusionSweep(set & theElems, SMESHDS_Mesh* aMesh = GetMeshDS(); TNodeOfNodeListMap mapNewNodes; + TElemOfVecOfNnlmiMap mapElemNewNodes; + TElemOfElemListMap newElemsMap; // loop on theElems set< const SMDS_MeshElement* >::iterator itElem; @@ -1725,11 +1911,12 @@ void SMESH_MeshEditor::ExtrusionSweep(set & theElems, { // check element type const SMDS_MeshElement* elem = (*itElem); - if ( !elem || - (elem->GetType() != SMDSAbs_Face && - elem->GetType() != SMDSAbs_Edge)) + if ( !elem ) continue; + vector & newNodesItVec = mapElemNewNodes[ elem ]; + newNodesItVec.reserve( elem->NbNodes() ); + // loop on elem nodes SMDS_ElemIteratorPtr itN = elem->nodesIterator(); while ( itN->more() ) { @@ -1737,25 +1924,349 @@ void SMESH_MeshEditor::ExtrusionSweep(set & theElems, // check if a node has been already sweeped const SMDS_MeshNode* node = static_cast( itN->next() ); - if (mapNewNodes.find( node ) != mapNewNodes.end() ) - continue; + TNodeOfNodeListMap::iterator nIt = mapNewNodes.find( node ); + if ( nIt == mapNewNodes.end() ) + { + nIt = mapNewNodes.insert( make_pair( node, list() )).first; + list& listNewNodes = nIt->second; - list& listNewNodes = mapNewNodes[ node ]; + // make new nodes + double coord[] = { node->X(), node->Y(), node->Z() }; + for ( int i = 0; i < theNbSteps; i++ ) { + aTrsf.Transforms( coord[0], coord[1], coord[2] ); + const SMDS_MeshNode * newNode = aMesh->AddNode( coord[0], coord[1], coord[2] ); + listNewNodes.push_back( newNode ); + } + } + newNodesItVec.push_back( nIt ); + } + // make new elements + sweepElement( aMesh, elem, newNodesItVec, newElemsMap[elem] ); + } - // make new nodes - double coord[3]; - coord[0] = node->X(); - coord[1] = node->Y(); - coord[2] = node->Z(); - for ( int i = 0; i < theNbSteps; i++ ) { - aTrsf.Transforms( coord[0], coord[1], coord[2] ); - const SMDS_MeshNode * newNode = aMesh->AddNode( coord[0], coord[1], coord[2] ); - listNewNodes.push_back( newNode ); + makeWalls( aMesh, mapNewNodes, newElemsMap, mapElemNewNodes, theElems ); + +} + +class SMESH_MeshEditor_PathPoint { +public: + SMESH_MeshEditor_PathPoint() { + myPnt.SetCoord(99., 99., 99.); + myTgt.SetCoord(1.,0.,0.); + myAngle=0.; + myPrm=0.; + } + void SetPnt(const gp_Pnt& aP3D){ + myPnt=aP3D; + } + void SetTangent(const gp_Dir& aTgt){ + myTgt=aTgt; + } + void SetAngle(const double& aBeta){ + myAngle=aBeta; + } + void SetParameter(const double& aPrm){ + myPrm=aPrm; + } + const gp_Pnt& Pnt()const{ + return myPnt; + } + const gp_Dir& Tangent()const{ + return myTgt; + } + double Angle()const{ + return myAngle; + } + double Parameter()const{ + return myPrm; + } + +protected: + gp_Pnt myPnt; + gp_Dir myTgt; + double myAngle; + double myPrm; +}; + +//======================================================================= +//function : ExtrusionAlongTrack +//purpose : +//======================================================================= +int SMESH_MeshEditor::ExtrusionAlongTrack (std::set & theElements, + SMESH_subMesh* theTrack, + const SMDS_MeshNode* theN1, + const bool theHasAngles, + std::list& theAngles, + const bool theHasRefPoint, + const gp_Pnt& theRefPoint) +{ + MESSAGE("SMESH_MeshEditor::ExtrusionAlongTrack") + int j, iErr, aNbTP, aNbAngles, aNbE, aNb; + double aT1, aT2, aT, aAngle, aX, aY, aZ; + std::list aPrms; + std::list::iterator aItD; + std::set< const SMDS_MeshElement* >::iterator itElem; + + Standard_Real aTx1, aTx2, aL2, aTolVec, aTolVec2; + gp_Pnt aP3D, aV0; + gp_Vec aVec; + gp_XYZ aGC; + Handle(Geom_Curve) aC3D; + TopoDS_Edge aTrackEdge; + TopoDS_Vertex aV1, aV2; + + SMDS_ElemIteratorPtr aItE; + SMDS_NodeIteratorPtr aItN; + SMDSAbs_ElementType aTypeE; + + TNodeOfNodeListMap mapNewNodes; + TElemOfVecOfNnlmiMap mapElemNewNodes; + TElemOfElemListMap newElemsMap; + + aTolVec=1.e-7; + aTolVec2=aTolVec*aTolVec; + iErr=0; + + // 1. Check data + aNbE=theElements.size(); + if ( !aNbE ) { + iErr = 10; // nothing to do + return iErr; + } + + // 1.1 Track Pattern + ASSERT( theTrack ); + + SMESHDS_SubMesh* pSubMeshDS=theTrack->GetSubMeshDS(); + + if ( !pSubMeshDS->Contains( theN1 ) ) { + iErr = 2; // No match found for start node + return iErr; + } + + aItE = pSubMeshDS->GetElements(); + while ( aItE->more() ) { + const SMDS_MeshElement* pE = aItE->next(); + aTypeE = pE->GetType(); + if ( aTypeE != SMDSAbs_Edge ) { + iErr = 3; // Pattern must contain links only + return iErr; + } + } + + const TopoDS_Shape& aS = theTrack->GetSubShape(); + if ( aS.ShapeType() != TopAbs_EDGE) { + iErr = 3; // Sub shape for the Pattern must be an Edge + return iErr; + aTrackEdge = TopoDS::Edge( aS ); + if ( BRep_Tool::Degenerated( aTrackEdge ) ) { + iErr = 4; // the Edge must not be degenerated + return iErr; + } + } + + TopExp::Vertices( aTrackEdge, aV1, aV2 ); + aT1=BRep_Tool::Parameter( aV1, aTrackEdge ); + aT2=BRep_Tool::Parameter( aV2, aTrackEdge ); + + aItN = myMesh->GetSubMesh( aV1 )->GetSubMeshDS()->GetNodes(); + const SMDS_MeshNode* aN1 = aItN->next(); + + aItN = myMesh->GetSubMesh( aV2 )->GetSubMeshDS()->GetNodes(); + const SMDS_MeshNode* aN2 = aItN->next(); + + if ( !( aN1 == theN1 || aN2 == theN1 ) ) { + iErr = 5; // starting node must be aN1 or aN2 + return iErr; + } + + aNbTP = pSubMeshDS->NbNodes() + 2; + + // 1.2. Angles + vector aAngles( aNbTP ); + + if ( theHasAngles ) { + aNbAngles = theAngles.size(); + if ( aNbTP != aNbAngles ) { + iErr = 6; // number of Angles does not match to the number of track points + return iErr; + } + aItD = theAngles.begin(); + for ( j=0; aItD != aPrms.end(); ++aItD, ++j ) { + aAngle = *aItD; + aAngles[j] = aAngle; + } + } + else { + for ( j=0; j < aNbTP; ++j ) { + aAngles[j] = 0.; + } + } + + // 2. Collect parameters on the track edge + aPrms.push_back( aT1 ); + aPrms.push_back( aT2 ); + + aItN = pSubMeshDS->GetNodes(); + while ( aItN->more() ) { + const SMDS_MeshNode* pNode = aItN->next(); + const SMDS_EdgePosition* pEPos = + static_cast( pNode->GetPosition().get() ); + aT = pEPos->GetUParameter(); + aPrms.push_back( aT ); + } + + // sort parameters + aPrms.sort(); + if ( aN1 == theN1 ) { + if ( aT1 > aT2 ) { + aPrms.reverse(); + } + } + else { + if ( aT2 > aT1 ) { + aPrms.reverse(); + } + } + + // 3. Path Points + SMESH_MeshEditor_PathPoint aPP; + vector aPPs( aNbTP ); + // + aC3D = BRep_Tool::Curve( aTrackEdge, aTx1, aTx2 ); + // + aItD = aPrms.begin(); + for ( j=0; aItD != aPrms.end(); ++aItD, ++j ) { + aT = *aItD; + aC3D->D1( aT, aP3D, aVec ); + aL2 = aVec.SquareMagnitude(); + if ( aL2 < aTolVec2 ) { + iErr = 20; // can not obtain the tangent; + return iErr; + } + gp_Dir aTgt( aVec ); + aAngle = aAngles[j]; + + aPP.SetPnt( aP3D ); + aPP.SetTangent( aTgt ); + aPP.SetAngle( aAngle ); + aPP.SetParameter( aT ); + aPPs[j]=aPP; + } + + // 3. Center of rotation aV0 + aV0 = theRefPoint; + if ( !theHasRefPoint ) { + aNb = 0; + aGC.SetCoord( 0.,0.,0. ); + + itElem = theElements.begin(); + for ( ; itElem != theElements.end(); itElem++ ) { + const SMDS_MeshElement* elem = (*itElem); + + SMDS_ElemIteratorPtr itN = elem->nodesIterator(); + while ( itN->more() ) { + const SMDS_MeshNode* node = static_cast( itN->next() ); + aX = node->X(); + aY = node->Y(); + aZ = node->Z(); + + if ( mapNewNodes.find( node ) == mapNewNodes.end() ) { + list aLNx; + mapNewNodes[node] = aLNx; + // + gp_XYZ aXYZ( aX, aY, aZ ); + aGC += aXYZ; + ++aNb; + } } } + aGC /= aNb; + aV0.SetXYZ( aGC ); + } // if (!theHasRefPoint) { + mapNewNodes.clear(); + + // 4. Processing the elements + SMESHDS_Mesh* aMesh = GetMeshDS(); + + for ( itElem = theElements.begin(); itElem != theElements.end(); itElem++ ) { + // check element type + const SMDS_MeshElement* elem = (*itElem); + aTypeE = elem->GetType(); + if ( !elem || ( aTypeE != SMDSAbs_Face && aTypeE != SMDSAbs_Edge ) ) + continue; + + vector & newNodesItVec = mapElemNewNodes[ elem ]; + newNodesItVec.reserve( elem->NbNodes() ); + + // loop on elem nodes + SMDS_ElemIteratorPtr itN = elem->nodesIterator(); + while ( itN->more() ) { + + // check if a node has been already processed + const SMDS_MeshNode* node = + static_cast( itN->next() ); + TNodeOfNodeListMap::iterator nIt = mapNewNodes.find( node ); + if ( nIt == mapNewNodes.end() ) { + nIt = mapNewNodes.insert( make_pair( node, list() )).first; + list& listNewNodes = nIt->second; + + // make new nodes + aX = node->X(); aY = node->Y(); aZ = node->Z(); + + Standard_Real aAngle1x; + gp_Pnt aP0x, aP1x, aPN0, aPN1, aV0x, aV1x; + gp_Ax1 anAx1; + + aV0x = aV0; + aPN0.SetCoord(aX, aY, aZ); + + const SMESH_MeshEditor_PathPoint& aPP0 = aPPs[0]; + aP0x = aPP0.Pnt(); + + for ( j = 1; j < aNbTP; ++j ) { + const SMESH_MeshEditor_PathPoint& aPP1 = aPPs[j]; + aP1x = aPP1.Pnt(); + const gp_Dir& aDT1x = aPP1.Tangent(); + aAngle1x = aPP1.Angle(); + + gp_Trsf aTrsf, aTrsfRot; + // Translation + gp_Vec aV01x( aP0x, aP1x ); + aTrsf.SetTranslation( aV01x ); + + // traslated point + aV1x = aV0x.Transformed( aTrsf ); + aPN1 = aPN0.Transformed( aTrsf ); + + if ( theHasAngles ) { + anAx1.SetLocation( aV1x ); + anAx1.SetDirection( aDT1x ); + aTrsfRot.SetRotation( anAx1, aAngle1x ); + + aPN1 = aPN1.Transformed( aTrsfRot ); + } + + // make new node + aX = aPN1.X(); + aY = aPN1.X(); + aZ = aPN1.X(); + const SMDS_MeshNode* newNode = aMesh->AddNode( aX, aY, aZ ); + listNewNodes.push_back( newNode ); + + aPN0 = aPN1; + aP0x = aP1x; + aV0x = aV1x; + } + } + newNodesItVec.push_back( nIt ); + } // make new elements - sweepElement( aMesh, elem, mapNewNodes ); + sweepElement( aMesh, elem, newNodesItVec, newElemsMap[elem] ); } + + makeWalls( aMesh, mapNewNodes, newElemsMap, mapElemNewNodes, theElements ); + return iErr; } //======================================================================= @@ -1928,17 +2439,26 @@ void SMESH_MeshEditor::Transform (set & theElems, //======================================================================= //function : FindCoincidentNodes //purpose : Return list of group of nodes close to each other within theTolerance +// Search among theNodes or in the whole mesh if theNodes is empty. //======================================================================= -void SMESH_MeshEditor::FindCoincidentNodes (const double theTolerance, - TListOfListOfNodes & theGroupsOfNodes) +void SMESH_MeshEditor::FindCoincidentNodes (set & theNodes, + const double theTolerance, + TListOfListOfNodes & theGroupsOfNodes) { double tol2 = theTolerance * theTolerance; list nodes; - SMDS_NodeIteratorPtr nIt = GetMeshDS()->nodesIterator(); - while ( nIt->more() ) - nodes.push_back( nIt->next() ); + if ( theNodes.empty() ) + { // get all nodes in the mesh + SMDS_NodeIteratorPtr nIt = GetMeshDS()->nodesIterator(); + while ( nIt->more() ) + nodes.push_back( nIt->next() ); + } + else + { + nodes.insert( nodes.end(), theNodes.begin(), theNodes.end() ); + } list::iterator it2, it1 = nodes.begin(); for ( ; it1 != nodes.end(); it1++ ) @@ -1995,7 +2515,7 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes) nodeNodeMap.insert( TNodeNodeMap::value_type( nToRemove, nToKeep )); if ( nToRemove != nToKeep ) { rmNodeIds.push_back( nToRemove->GetID() ); - addToSameGroups( nToKeep, nToRemove, aMesh ); + AddToSameGroups( nToKeep, nToRemove, aMesh ); } SMDS_ElemIteratorPtr invElemIt = nToRemove->GetInverseElementIterator(); @@ -2343,41 +2863,63 @@ void SMESH_MeshEditor::MergeEqualElements() Remove( rmElemIds, false ); } +//======================================================================= +//function : FindFaceInSet +//purpose : Return a face having linked nodes n1 and n2 and which is +// - not in avoidSet, +// - in elemSet provided that !elemSet.empty() +//======================================================================= + +const SMDS_MeshElement* + SMESH_MeshEditor::FindFaceInSet(const SMDS_MeshNode* n1, + const SMDS_MeshNode* n2, + const set& elemSet, + const set& avoidSet) + +{ + SMDS_ElemIteratorPtr invElemIt = n1->GetInverseElementIterator(); + while ( invElemIt->more() ) { // loop on inverse elements of n1 + const SMDS_MeshElement* elem = invElemIt->next(); + if (elem->GetType() != SMDSAbs_Face || + avoidSet.find( elem ) != avoidSet.end() ) + continue; + if ( !elemSet.empty() && elemSet.find( elem ) == elemSet.end()) + continue; + // get face nodes and find index of n1 + int i1, nbN = elem->NbNodes(), iNode = 0; + const SMDS_MeshNode* faceNodes[ nbN ], *n; + SMDS_ElemIteratorPtr nIt = elem->nodesIterator(); + while ( nIt->more() ) { + faceNodes[ iNode ] = static_cast( nIt->next() ); + if ( faceNodes[ iNode++ ] == n1 ) + i1 = iNode - 1; + } + // find a n2 linked to n1 + for ( iNode = 0; iNode < 2; iNode++ ) { + if ( iNode ) // node before n1 + n = faceNodes[ i1 == 0 ? nbN - 1 : i1 - 1 ]; + else // node after n1 + n = faceNodes[ i1 + 1 == nbN ? 0 : i1 + 1 ]; + if ( n == n2 ) + return elem; + } + } + return 0; +} + //======================================================================= //function : findAdjacentFace //purpose : //======================================================================= -#define CHECKIND(max,val) {if ( (val) >= (max) ) \ static const SMDS_MeshElement* findAdjacentFace(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2, const SMDS_MeshElement* elem) { - SMDS_ElemIteratorPtr invElemIt = n1->facesIterator(); - while ( invElemIt->more() ) { // loop on inverse elements of n1 - const SMDS_MeshElement* adjElem = invElemIt->next(); - if ( elem != adjElem ) { - // get face nodes and find index of n1 - int i1, nbN = adjElem->NbNodes(), iNode = 0; - const SMDS_MeshNode* faceNodes[ nbN ], *n; - SMDS_ElemIteratorPtr nIt = adjElem->nodesIterator(); - while ( nIt->more() ) { - faceNodes[ iNode ] = static_cast( nIt->next() ); - if ( faceNodes[ iNode++ ] == n1 ) - i1 = iNode - 1; - } - // find a n2 linked to n1 - for ( iNode = 0; iNode < 2; iNode++ ) { - if ( iNode ) // node before n1 - n = faceNodes[ i1 == 0 ? nbN - 1 : i1 - 1 ]; - else // node after n1 - n = faceNodes[ i1 + 1 == nbN ? 0 : i1 + 1 ]; - if ( n == n2 ) - return adjElem; - } - } - } - return 0; + set elemSet, avoidSet; + if ( elem ) + avoidSet.insert ( elem ); + SMESH_MeshEditor::FindFaceInSet( n1, n2, elemSet, avoidSet ); } //======================================================================= diff --git a/src/SMESH/SMESH_MeshEditor.hxx b/src/SMESH/SMESH_MeshEditor.hxx index 10b7f9fa9..3dc5173f6 100644 --- a/src/SMESH/SMESH_MeshEditor.hxx +++ b/src/SMESH/SMESH_MeshEditor.hxx @@ -41,6 +41,7 @@ class SMDS_MeshFace; class SMDS_MeshNode; class gp_Ax1; class gp_Vec; +class gp_Pnt; class SMESH_MeshEditor { public: @@ -121,18 +122,28 @@ class SMESH_MeshEditor { // Generate new elements by extrusion of theElements // by theStep by theNbSteps + int ExtrusionAlongTrack (std::set & theElements, + SMESH_subMesh* theTrackPattern, + const SMDS_MeshNode* theNodeStart, + const bool theHasAngles, + std::list& theAngles, + const bool theHasRefPoint, + const gp_Pnt& theRefPoint); + // Generate new elements by extrusion of theElements along path given by theTrackPattern, + // theHasAngles are the rotation angles, base point can be given by theRefPoint void Transform (std::set & theElements, const gp_Trsf& theTrsf, const bool theCopy); // Move or copy theElements applying theTrsf to their nodes - typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes; - void FindCoincidentNodes (const double theTolerance, - TListOfListOfNodes & theGroupsOfNodes); - // Return list of group of nodes close to each other within theTolerance + void FindCoincidentNodes (std::set & theNodes, + const double theTolerance, + TListOfListOfNodes & theGroupsOfNodes); + // Return list of group of nodes close to each other within theTolerance. + // Search among theNodes or in the whole mesh if theNodes is empty. void MergeNodes (TListOfListOfNodes & theNodeGroups); // In each group, the cdr of nodes are substituted by the first one @@ -220,7 +231,20 @@ class SMESH_MeshEditor { int theNodeIds[] ); // Set 8 nodes of a hexahedron in a good order. // Return success status - + + static void AddToSameGroups (const SMDS_MeshElement* elemToAdd, + const SMDS_MeshElement* elemInGroups, + SMESHDS_Mesh * aMesh); + // Add elemToAdd to the groups the elemInGroups belongs to + + static const SMDS_MeshElement* + FindFaceInSet(const SMDS_MeshNode* n1, + const SMDS_MeshNode* n2, + const std::set& elemSet, + const std::set& avoidSet); + // Return a face having linked nodes n1 and n2 and which is + // - not in avoidSet, + // - in elemSet provided that !elemSet.empty() int FindShape (const SMDS_MeshElement * theElem); // Return an index of the shape theElem is on diff --git a/src/SMESH/SMESH_Pattern.cxx b/src/SMESH/SMESH_Pattern.cxx index 06595678e..86f1d52ab 100644 --- a/src/SMESH/SMESH_Pattern.cxx +++ b/src/SMESH/SMESH_Pattern.cxx @@ -23,11 +23,16 @@ #include "SMESH_Pattern.hxx" -#include #include #include #include +#include +#include +#include +#include +#include #include +#include #include #include #include @@ -41,23 +46,24 @@ #include #include #include +#include #include #include #include #include #include -#include -#include -#include #include "SMDS_EdgePosition.hxx" #include "SMDS_FacePosition.hxx" #include "SMDS_MeshElement.hxx" +#include "SMDS_MeshFace.hxx" #include "SMDS_MeshNode.hxx" +#include "SMESHDS_Group.hxx" #include "SMESHDS_Mesh.hxx" #include "SMESHDS_SubMesh.hxx" -#include "SMESH_Mesh.hxx" #include "SMESH_Block.hxx" +#include "SMESH_Mesh.hxx" +#include "SMESH_MeshEditor.hxx" #include "SMESH_subMesh.hxx" #include "utilities.h" @@ -401,9 +407,6 @@ template struct TSizeCmp { template void sortBySize( list< list < T > > & theListOfList ) { if ( theListOfList.size() > 2 ) { - // keep the car - //list < T > & aFront = theListOfList.front(); - // sort the whole list TSizeCmp< T > SizeCmp; theListOfList.sort( SizeCmp ); } @@ -599,7 +602,7 @@ bool SMESH_Pattern::Load (SMESH_Mesh* theMesh, if ( nIdIt == nodePointIDMap.end() ) { elemPoints.push_back( iPoint ); - nodePointIDMap.insert( TNodePointIDMap::value_type( node, iPoint++ )); + nodePointIDMap.insert( make_pair( node, iPoint++ )); } else elemPoints.push_back( (*nIdIt).second ); @@ -684,7 +687,7 @@ bool SMESH_Pattern::Load (SMESH_Mesh* theMesh, myKeyPointIDs.push_back( iPoint ); SMDS_NodeIteratorPtr nIt = vSubMesh->GetNodes(); const SMDS_MeshNode* node = nIt->next(); - nodePointIDMap.insert( TNodePointIDMap::value_type( node, iPoint )); + nodePointIDMap.insert( make_pair( node, iPoint )); TPoint* keyPoint = &myPoints[ iPoint++ ]; vPoint.push_back( keyPoint ); @@ -724,7 +727,7 @@ bool SMESH_Pattern::Load (SMESH_Mesh* theMesh, TPoint* p = & myPoints[ iPoint ]; ePoints.push_back( p ); const SMDS_MeshNode* node = isForward ? (*unIt).second : (*unRIt).second; - nodePointIDMap.insert ( TNodePointIDMap::value_type( node, iPoint )); + nodePointIDMap.insert ( make_pair( node, iPoint )); if ( theProject ) p->myInitUV = project( node, projector ); @@ -748,7 +751,7 @@ bool SMESH_Pattern::Load (SMESH_Mesh* theMesh, myKeyPointIDs.push_back( iPoint ); SMDS_NodeIteratorPtr nIt = vSubMesh->GetNodes(); const SMDS_MeshNode* node = nIt->next(); - nodePointIDMap.insert( TNodePointIDMap::value_type( node, iPoint )); + nodePointIDMap.insert( make_pair( node, iPoint )); TPoint* keyPoint = &myPoints[ iPoint++ ]; vPoint2.push_back( keyPoint ); @@ -793,7 +796,7 @@ bool SMESH_Pattern::Load (SMESH_Mesh* theMesh, { const SMDS_MeshNode* node = static_cast( nIt->next() ); - nodePointIDMap.insert( TNodePointIDMap::value_type( node, iPoint )); + nodePointIDMap.insert( make_pair( node, iPoint )); TPoint* p = &myPoints[ iPoint++ ]; fPoints.push_back( p ); if ( theProject ) @@ -2244,7 +2247,6 @@ bool SMESH_Pattern::Apply (const TopoDS_Face& theFace, } int nbVertices = myShapeIDMap.Extent(); - //int nbSeamShapes = 0; // count twice seam edge and its vertices for ( elIt = eList.begin(); elIt != eList.end(); elIt++ ) myShapeIDMap.Add( *elIt ); @@ -2441,6 +2443,461 @@ bool SMESH_Pattern::Apply (const TopoDS_Face& theFace, return setErrorCode( ERR_OK ); } +//======================================================================= +//function : Apply +//purpose : Compute nodes coordinates applying +// the loaded pattern to . The first key-point +// will be mapped into -th node +//======================================================================= + +bool SMESH_Pattern::Apply (const SMDS_MeshFace* theFace, + const int theNodeIndexOnKeyPoint1, + const bool theReverse) +{ + MESSAGE(" ::Apply(MeshFace) " ); + + if ( !IsLoaded() ) { + MESSAGE( "Pattern not loaded" ); + return setErrorCode( ERR_APPL_NOT_LOADED ); + } + + // check nb of nodes + if (theFace->NbNodes() != myNbKeyPntInBoundary.front() ) { + MESSAGE( myKeyPointIDs.size() << " != " << theFace->NbNodes() ); + return setErrorCode( ERR_APPL_BAD_NB_VERTICES ); + } + + // find points on edges, it fills myNbKeyPntInBoundary + if ( !findBoundaryPoints() ) + return false; + + // check that there are no holes in a pattern + if (myNbKeyPntInBoundary.size() > 1 ) { + return setErrorCode( ERR_APPL_BAD_NB_VERTICES ); + } + + // Define the nodes order + + list< const SMDS_MeshNode* > nodes; + list< const SMDS_MeshNode* >::iterator n = nodes.end(); + SMDS_ElemIteratorPtr noIt = theFace->nodesIterator(); + int iSub = 0; + while ( noIt->more() ) { + const SMDS_MeshNode* node = static_cast( noIt->next() ); + nodes.push_back( node ); + if ( iSub++ == theNodeIndexOnKeyPoint1 ) + n = --nodes.end(); + } + if ( n != nodes.end() ) { + if ( theReverse ) { + if ( n != --nodes.end() ) + nodes.splice( nodes.begin(), nodes, ++n, nodes.end() ); + nodes.reverse(); + } + else if ( n != nodes.begin() ) + nodes.splice( nodes.end(), nodes, nodes.begin(), n ); + } + list< gp_XYZ > xyzList; + myOrderedNodes.resize( theFace->NbNodes() ); + for ( iSub = 0, n = nodes.begin(); n != nodes.end(); ++n ) { + xyzList.push_back( gp_XYZ( (*n)->X(), (*n)->Y(), (*n)->Z() )); + myOrderedNodes[ iSub++] = *n; + } + + // Define a face plane + + list< gp_XYZ >::iterator xyzIt = xyzList.begin(); + gp_Pnt P ( *xyzIt++ ); + gp_Vec Vx( P, *xyzIt++ ), N; + do { + N = Vx ^ gp_Vec( P, *xyzIt++ ); + } while ( N.SquareMagnitude() <= DBL_MIN && xyzIt != xyzList.end() ); + if ( N.SquareMagnitude() <= DBL_MIN ) + return setErrorCode( ERR_APPLF_BAD_FACE_GEOM ); + gp_Ax2 pos( P, N, Vx ); + + // Compute UV of key-points on a plane + for ( xyzIt = xyzList.begin(), iSub = 1; xyzIt != xyzList.end(); xyzIt++, iSub++ ) + { + gp_Vec vec ( pos.Location(), *xyzIt ); + TPoint* p = getShapePoints( iSub ).front(); + p->myUV.SetX( vec * pos.XDirection() ); + p->myUV.SetY( vec * pos.YDirection() ); + p->myXYZ = *xyzIt; + } + + // points on edges to be used for UV computation of in-face points + list< list< TPoint* > > edgesPointsList; + edgesPointsList.push_back( list< TPoint* >() ); + list< TPoint* > * edgesPoints = & edgesPointsList.back(); + list< TPoint* >::iterator pIt; + + // compute UV and XYZ of points on edges + + for ( xyzIt = xyzList.begin(); xyzIt != xyzList.end(); iSub++ ) + { + gp_XYZ& xyz1 = *xyzIt++; + gp_XYZ& xyz2 = ( xyzIt != xyzList.end() ) ? *xyzIt : xyzList.front(); + + list< TPoint* > & ePoints = getShapePoints( iSub ); + ePoints.back()->myInitU = 1.0; + list< TPoint* >::const_iterator pIt = ++ePoints.begin(); + while ( *pIt != ePoints.back() ) + { + TPoint* p = *pIt++; + p->myXYZ = xyz1 * ( 1 - p->myInitU ) + xyz2 * p->myInitU; + gp_Vec vec ( pos.Location(), p->myXYZ ); + p->myUV.SetX( vec * pos.XDirection() ); + p->myUV.SetY( vec * pos.YDirection() ); + } + // collect on-edge points (excluding the last one) + edgesPoints->insert( edgesPoints->end(), ePoints.begin(), --ePoints.end()); + } + + // Compute UV and XYZ of in-face points + + // try to use a simple algo to compute UV + list< TPoint* > & fPoints = getShapePoints( iSub ); + bool isDeformed = false; + for ( pIt = fPoints.begin(); !isDeformed && pIt != fPoints.end(); pIt++ ) + if ( !compUVByIsoIntersection( edgesPointsList, (*pIt)->myInitUV, + (*pIt)->myUV, isDeformed )) { + MESSAGE("cant Apply(face)"); + return false; + } + // try to use a complex algo if it is a difficult case + if ( isDeformed && !compUVByElasticIsolines( edgesPointsList, fPoints )) + { + for ( ; pIt != fPoints.end(); pIt++ ) // continue with the simple algo + if ( !compUVByIsoIntersection( edgesPointsList, (*pIt)->myInitUV, + (*pIt)->myUV, isDeformed )) { + MESSAGE("cant Apply(face)"); + return false; + } + } + + for ( pIt = fPoints.begin(); pIt != fPoints.end(); pIt++ ) + { + (*pIt)->myXYZ = ElSLib::PlaneValue( (*pIt)->myUV.X(), (*pIt)->myUV.Y(), pos ); + } + + myIsComputed = true; + + return setErrorCode( ERR_OK ); +} + +//======================================================================= +//function : undefinedXYZ +//purpose : +//======================================================================= + +static const gp_XYZ& undefinedXYZ() +{ + static gp_XYZ xyz( 1.e100, 0., 0. ); + return xyz; +} + +//======================================================================= +//function : isDefined +//purpose : +//======================================================================= + +inline static bool isDefined(const gp_XYZ& theXYZ) +{ + return theXYZ.X() < 1.e100; +} + +//======================================================================= +//function : mergePoints +//purpose : Look for coincident points between myXYZs indexed with +// list of each element of xyzIndGroups. Coincident indices +// are merged in myElemXYZIDs. +//======================================================================= + +void SMESH_Pattern::mergePoints (map > >& indGroups, + map< int, list< list< int >* > > & reverseConnectivity) +{ + map< TNodeSet, list< list< int > > >::iterator indListIt; + for ( indListIt = indGroups.begin(); indListIt != indGroups.end(); indListIt++ ) + { + list > groups = indListIt->second; + if ( groups.size() < 2 ) + continue; + +// const TNodeSet & nodes = indListIt->first; +// TNodeSet::const_iterator n = nodes.begin(); +// for ( ; n != nodes.end(); n++ ) +// cout << *n ; + + // find tolerance + Bnd_Box box; + list< int >& indices = groups.front(); + list< int >::iterator ind, ind1, ind2; + for ( ind = indices.begin(); ind != indices.end(); ind++ ) + box.Add( gp_Pnt( myXYZ[ *ind ])); + double x, y, z, X, Y, Z; + box.Get( x, y, z, X, Y, Z ); + gp_Pnt p( x, y, z ), P( X, Y, Z ); + double tol2 = 1.e-4 * p.SquareDistance( P ); + + // compare points, replace indices + + list< list< int > >::iterator grpIt1, grpIt2; + for ( grpIt1 = groups.begin(); grpIt1 != groups.end(); grpIt1++ ) + { + list< int >& indices1 = *grpIt1; + grpIt2 = grpIt1; + for ( grpIt2++; grpIt2 != groups.end(); grpIt2++ ) + { + list< int >& indices2 = *grpIt2; + for ( ind1 = indices1.begin(); ind1 != indices1.end(); ind1++ ) + { + gp_XYZ& p1 = myXYZ[ *ind1 ]; + ind2 = indices2.begin(); + while ( ind2 != indices2.end() ) + { + gp_XYZ& p2 = myXYZ[ *ind2 ]; + //MESSAGE("COMP: " << *ind1 << " " << *ind2 << " X: " << p2.X() << " tol2: " << tol2); + if ( ( p1 - p2 ).SquareModulus() <= tol2 ) + { + ASSERT( reverseConnectivity.find( *ind2 ) != reverseConnectivity.end() ); + list< list< int >* > & elemXYZIDsList = reverseConnectivity[ *ind2 ]; + list< list< int >* >::iterator elemXYZIDs = elemXYZIDsList.begin(); + for ( ; elemXYZIDs != elemXYZIDsList.end(); elemXYZIDs++ ) + { + ind = find( (*elemXYZIDs)->begin(), (*elemXYZIDs)->end(), *ind2 ); + //MESSAGE( " Replace " << *ind << " with " << *ind1 ); + myXYZ[ *ind ] = undefinedXYZ(); + *ind = *ind1; + } + ind2 = indices2.erase( ind2 ); + } + else + ind2++; + } + } + } + } + } +} + +//======================================================================= +//function : Apply +//purpose : Compute nodes coordinates applying +// the loaded pattern to . The first key-point +// will be mapped into -th node +//======================================================================= + +bool SMESH_Pattern::Apply (std::set theFaces, + const int theNodeIndexOnKeyPoint1, + const bool theReverse) +{ + MESSAGE(" ::Apply(set) " ); + + if ( !IsLoaded() ) { + MESSAGE( "Pattern not loaded" ); + return setErrorCode( ERR_APPL_NOT_LOADED ); + } + + // find points on edges, it fills myNbKeyPntInBoundary + if ( !findBoundaryPoints() ) + return false; + + // check that there are no holes in a pattern + if (myNbKeyPntInBoundary.size() > 1 ) { + return setErrorCode( ERR_APPL_BAD_NB_VERTICES ); + } + + myXYZ.clear(); + myElemXYZIDs.clear(); + myXYZIdToNodeMap.clear(); + myElements.clear(); + + myXYZ.resize( myPoints.size() * theFaces.size(), undefinedXYZ() ); + myElements.reserve( theFaces.size() ); + + // to find point index + map< TPoint*, int > pointIndex; + for ( int i = 0; i < myPoints.size(); i++ ) + pointIndex.insert( make_pair( & myPoints[ i ], i )); + + // to merge nodes on edges of the elements being refined + typedef set TLink; + map< TLink, list< list< int > > > linkPointIndListMap; + map< int, list< list< int >* > > reverseConnectivity; + + int ind1 = 0; // lowest point index for a face + + // apply to each face in theFaces set + set::iterator face = theFaces.begin(); + for ( ; face != theFaces.end(); ++face ) + { + if ( !Apply( *face, theNodeIndexOnKeyPoint1, theReverse )) { + MESSAGE( "Failed on " << *face ); + continue; + } + myElements.push_back( *face ); + + // store computed points belonging to elements + list< list< int > >::iterator ll = myElemPointIDs.begin(); + for ( ; ll != myElemPointIDs.end(); ++ll ) + { + myElemXYZIDs.push_back(); + list< int >& xyzIds = myElemXYZIDs.back(); + list< int >& pIds = *ll; + for ( list::iterator id = pIds.begin(); id != pIds.end(); id++ ) { + int pIndex = *id + ind1; + xyzIds.push_back( pIndex ); + myXYZ[ pIndex ] = myPoints[ *id ].myXYZ.XYZ(); + reverseConnectivity[ pIndex ].push_back( & xyzIds ); + } + } + // put points on links to linkPointIndListMap + int nbNodes = (*face)->NbNodes(), eID = nbNodes + 1; + for ( int i = 0; i < nbNodes; i++ ) + { + const SMDS_MeshNode* n1 = myOrderedNodes[ i ]; + const SMDS_MeshNode* n2 = myOrderedNodes[ i + 1 == nbNodes ? 0 : i + 1 ]; + // make a link of node pointers + TLink link; + link.insert( n1 ); + link.insert( n2 ); + // add the link to the map + list< list< int > >& groups = linkPointIndListMap[ link ]; + groups.push_back(); + list< int >& indList = groups.back(); + list< TPoint* > & linkPoints = getShapePoints( eID++ ); + list< TPoint* >::iterator p = linkPoints.begin(); + // map the first link point to n1 + myXYZIdToNodeMap[ pointIndex[ *p ] + ind1 ] = n1; + // add points to the map excluding the end points + for ( p++; *p != linkPoints.back(); p++ ) + indList.push_back( pointIndex[ *p ] + ind1 ); + } + ind1 += myPoints.size(); + } + + mergePoints( linkPointIndListMap, reverseConnectivity ); + + return !myElemXYZIDs.empty(); +} + +//======================================================================= +//function : Apply +//purpose : Compute nodes coordinates applying +// the loaded pattern to . The (0,0,0) key-point +// will be mapped into -th node. The +// (0,0,1) key-point will be mapped into -th +// node. +//======================================================================= + +bool SMESH_Pattern::Apply (std::set theVolumes, + const int theNode000Index, + const int theNode001Index) +{ + MESSAGE(" ::Apply(set) " ); + + if ( !IsLoaded() ) { + MESSAGE( "Pattern not loaded" ); + return setErrorCode( ERR_APPL_NOT_LOADED ); + } + + // bind ID to points + if ( !findBoundaryPoints() ) + return false; + + // check that there are no holes in a pattern + if (myNbKeyPntInBoundary.size() > 1 ) { + return setErrorCode( ERR_APPL_BAD_NB_VERTICES ); + } + + myXYZ.clear(); + myElemXYZIDs.clear(); + myXYZIdToNodeMap.clear(); + myElements.clear(); + + myXYZ.resize( myPoints.size() * theVolumes.size(), undefinedXYZ() ); + myElements.reserve( theVolumes.size() ); + + // to find point index + map< TPoint*, int > pointIndex; + for ( int i = 0; i < myPoints.size(); i++ ) + pointIndex.insert( make_pair( & myPoints[ i ], i )); + + // to merge nodes on edges and faces of the elements being refined + map< TNodeSet, list< list< int > > > subPointIndListMap; + map< int, list< list< int >* > > reverseConnectivity; + + int ind1 = 0; // lowest point index for an element + + // apply to each element in theVolumes set + set::iterator vol = theVolumes.begin(); + for ( ; vol != theVolumes.end(); ++vol ) + { + if ( !Apply( *vol, theNode000Index, theNode001Index )) { + MESSAGE( "Failed on " << *vol ); + continue; + } + myElements.push_back( *vol ); + + // store computed points belonging to elements + list< list< int > >::iterator ll = myElemPointIDs.begin(); + for ( ; ll != myElemPointIDs.end(); ++ll ) + { + myElemXYZIDs.push_back(); + list< int >& xyzIds = myElemXYZIDs.back(); + list< int >& pIds = *ll; + for ( list::iterator id = pIds.begin(); id != pIds.end(); id++ ) { + int pIndex = *id + ind1; + xyzIds.push_back( pIndex ); + myXYZ[ pIndex ] = myPoints[ *id ].myXYZ.XYZ(); + reverseConnectivity[ pIndex ].push_back( & xyzIds ); + } + } + // put points on edges and faces to subPointIndListMap + for ( int Id = SMESH_Block::ID_V000; Id <= SMESH_Block::ID_F1yz; Id++ ) + { + // make a set of sub-points + TNodeSet subNodes; + vector< int > subIDs; + if ( SMESH_Block::IsVertexID( Id )) { + // use nodes of refined volumes for merge + } + else if ( SMESH_Block::IsEdgeID( Id )) { + SMESH_Block::GetEdgeVertexIDs( Id, subIDs ); + subNodes.insert( myOrderedNodes[ subIDs.front() - 1 ]); + subNodes.insert( myOrderedNodes[ subIDs.back() - 1 ]); + } + else { + SMESH_Block::GetFaceEdgesIDs( Id, subIDs ); + int e1 = subIDs[ 0 ], e2 = subIDs[ 1 ]; + SMESH_Block::GetEdgeVertexIDs( e1, subIDs ); + subNodes.insert( myOrderedNodes[ subIDs.front() - 1 ]); + subNodes.insert( myOrderedNodes[ subIDs.back() - 1 ]); + SMESH_Block::GetEdgeVertexIDs( e2, subIDs ); + subNodes.insert( myOrderedNodes[ subIDs.front() - 1 ]); + subNodes.insert( myOrderedNodes[ subIDs.back() - 1 ]); + } + list< list< int > >& groups = subPointIndListMap[ subNodes ]; + groups.push_back(); + list< int >& indList = groups.back(); + // add points + list< TPoint* > & points = getShapePoints( Id ); + list< TPoint* >::iterator p = points.begin(); + if ( subNodes.empty() ) // vertex case + myXYZIdToNodeMap[ pointIndex[ *p ] + ind1 ] = myOrderedNodes[ Id - 1 ]; + else + for ( ; p != points.end(); p++ ) + indList.push_back( pointIndex[ *p ] + ind1 ); + } + ind1 += myPoints.size(); + } + + mergePoints( subPointIndListMap, reverseConnectivity ); + + return !myElemXYZIDs.empty(); +} + //======================================================================= //function : Load //purpose : Create a pattern from the mesh built on @@ -2486,7 +2943,7 @@ bool SMESH_Pattern::Load (SMESH_Mesh* theMesh, // store a node and a point while ( nIt->more() ) { const SMDS_MeshNode* node = static_cast( nIt->next() ); - nodePointIDMap.insert( TNodePointIDMap::value_type( node, iPoint )); + nodePointIDMap.insert( make_pair( node, iPoint )); if ( block.IsVertexID( shapeID )) myKeyPointIDs.push_back( iPoint ); TPoint* p = & myPoints[ iPoint++ ]; @@ -2620,6 +3077,56 @@ bool SMESH_Pattern::Apply (const TopoDS_Shell& theBlock, return setErrorCode( ERR_OK ); } +//======================================================================= +//function : Apply +//purpose : Compute nodes coordinates applying +// the loaded pattern to . The (0,0,0) key-point +// will be mapped into -th node. The +// (0,0,1) key-point will be mapped into -th +// node. +//======================================================================= + +bool SMESH_Pattern::Apply (const SMDS_MeshVolume* theVolume, + const int theNode000Index, + const int theNode001Index) +{ + MESSAGE(" ::Apply(MeshVolume) " ); + + if (!findBoundaryPoints()) // bind ID to points + return false; + + SMESH_Block block; // bind ID to shape + if (!block.LoadMeshBlock( theVolume, theNode000Index, theNode001Index, myOrderedNodes )) + return setErrorCode( ERR_APPLV_BAD_SHAPE ); + // compute XYZ of points on shapes + + for ( int ID = SMESH_Block::ID_V000; ID <= SMESH_Block::ID_Shell; ID++ ) + { + list< TPoint* > & shapePoints = getShapePoints( ID ); + list< TPoint* >::iterator pIt = shapePoints.begin(); + + if ( block.IsVertexID( ID )) + for ( ; pIt != shapePoints.end(); pIt++ ) { + block.VertexPoint( ID, (*pIt)->myXYZ.ChangeCoord() ); + } + else if ( block.IsEdgeID( ID )) + for ( ; pIt != shapePoints.end(); pIt++ ) { + block.EdgePoint( ID, (*pIt)->myInitXYZ, (*pIt)->myXYZ.ChangeCoord() ); + } + else if ( block.IsFaceID( ID )) + for ( ; pIt != shapePoints.end(); pIt++ ) { + block.FacePoint( ID, (*pIt)->myInitXYZ, (*pIt)->myXYZ.ChangeCoord() ); + } + else + for ( ; pIt != shapePoints.end(); pIt++ ) + block.ShellPoint( (*pIt)->myInitXYZ, (*pIt)->myXYZ.ChangeCoord() ); + } // loop on block sub-shapes + + myIsComputed = true; + + return setErrorCode( ERR_OK ); +} + //======================================================================= //function : MakeMesh //purpose : Create nodes and elements in using nodes @@ -2633,78 +3140,130 @@ bool SMESH_Pattern::MakeMesh(SMESH_Mesh* theMesh) return setErrorCode( ERR_MAKEM_NOT_COMPUTED ); SMESHDS_Mesh* aMeshDS = theMesh->GetMeshDS(); + SMESH_MeshEditor editor( theMesh ); // clear elements and nodes existing on myShape - SMESH_subMesh * aSubMesh = theMesh->GetSubMeshContaining( myShape ); - SMESHDS_SubMesh * aSubMeshDS = aMeshDS->MeshElements( myShape ); - if ( aSubMesh ) - aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN ); - else if ( aSubMeshDS ) + + if ( !myShape.IsNull() ) { - SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements(); - while ( eIt->more() ) - aMeshDS->RemoveElement( eIt->next() ); - SMDS_NodeIteratorPtr nIt = aSubMeshDS->GetNodes(); - while ( nIt->more() ) - aMeshDS->RemoveNode( static_cast( nIt->next() )); + SMESH_subMesh * aSubMesh = theMesh->GetSubMeshContaining( myShape ); + SMESHDS_SubMesh * aSubMeshDS = aMeshDS->MeshElements( myShape ); + if ( aSubMesh ) + aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN ); + else if ( aSubMeshDS ) + { + SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements(); + while ( eIt->more() ) + aMeshDS->RemoveElement( eIt->next() ); + SMDS_NodeIteratorPtr nIt = aSubMeshDS->GetNodes(); + while ( nIt->more() ) + aMeshDS->RemoveNode( static_cast( nIt->next() )); + } } + bool onMeshElements = ( !myElements.empty() ); + // loop on sub-shapes of myShape: create nodes and build point-node map - typedef map< TPoint*, const SMDS_MeshNode* > TPointNodeMap; - TPointNodeMap pointNodeMap; - map< int, list< TPoint* > >::iterator idPointIt = myShapeIDToPointsMap.begin(); - for ( ; idPointIt != myShapeIDToPointsMap.end(); idPointIt++ ) + + vector< const SMDS_MeshNode* > nodesVector; + map< TPoint*, const SMDS_MeshNode* > pointNodeMap; + if ( onMeshElements ) + { + nodesVector.resize( myXYZ.size() ); + for ( int i = 0; i < myXYZ.size(); ++i ) { + map< int, const SMDS_MeshNode*>::iterator idNode = myXYZIdToNodeMap.find( i ); + if ( idNode != myXYZIdToNodeMap.end() ) + nodesVector[ i ] = idNode->second; + else if ( isDefined( myXYZ[ i ] )) + nodesVector[ i ] = aMeshDS->AddNode (myXYZ[ i ].X(), + myXYZ[ i ].Y(), + myXYZ[ i ].Z()); + } + } + else { - const TopoDS_Shape & S = myShapeIDMap( (*idPointIt).first ); - list< TPoint* > & points = (*idPointIt).second; - SMESHDS_SubMesh * subMeshDS = aMeshDS->MeshElements( S ); - SMESH_subMesh * subMesh = theMesh->GetSubMeshContaining( myShape ); - list< TPoint* >::iterator pIt = points.begin(); - for ( ; pIt != points.end(); pIt++ ) + map< int, list< TPoint* > >::iterator idPointIt = myShapeIDToPointsMap.begin(); + for ( ; idPointIt != myShapeIDToPointsMap.end(); idPointIt++ ) { - TPoint* point = *pIt; - if ( pointNodeMap.find( point ) != pointNodeMap.end() ) - continue; - SMDS_MeshNode* node = aMeshDS->AddNode (point->myXYZ.X(), - point->myXYZ.Y(), - point->myXYZ.Z()); - pointNodeMap.insert( TPointNodeMap::value_type( point, node )); - if ( subMeshDS ) { - switch ( S.ShapeType() ) { - case TopAbs_VERTEX: { - aMeshDS->SetNodeOnVertex( node, TopoDS::Vertex( S )); - break; - } - case TopAbs_EDGE: { - aMeshDS->SetNodeOnEdge( node, TopoDS::Edge( S )); - SMDS_EdgePosition* epos = - dynamic_cast(node->GetPosition().get()); - epos->SetUParameter( point->myU ); - break; - } - case TopAbs_FACE: { - aMeshDS->SetNodeOnFace( node, TopoDS::Face( S )); - SMDS_FacePosition* pos = - dynamic_cast(node->GetPosition().get()); - pos->SetUParameter( point->myUV.X() ); - pos->SetVParameter( point->myUV.Y() ); - break; - } - default: - aMeshDS->SetNodeInVolume( node, TopoDS::Shell( S )); + TopoDS_Shape S; + SMESHDS_SubMesh * subMeshDS = 0; + if ( !myShapeIDMap.IsEmpty() ) { + S = myShapeIDMap( idPointIt->first ); + subMeshDS = aMeshDS->MeshElements( S ); + } + list< TPoint* > & points = idPointIt->second; + list< TPoint* >::iterator pIt = points.begin(); + for ( ; pIt != points.end(); pIt++ ) + { + TPoint* point = *pIt; + if ( pointNodeMap.find( point ) != pointNodeMap.end() ) + continue; + SMDS_MeshNode* node = aMeshDS->AddNode (point->myXYZ.X(), + point->myXYZ.Y(), + point->myXYZ.Z()); + pointNodeMap.insert( make_pair( point, node )); + if ( subMeshDS ) { + switch ( S.ShapeType() ) { + case TopAbs_VERTEX: { + aMeshDS->SetNodeOnVertex( node, TopoDS::Vertex( S )); + break; + } + case TopAbs_EDGE: { + aMeshDS->SetNodeOnEdge( node, TopoDS::Edge( S )); + SMDS_EdgePosition* epos = + dynamic_cast(node->GetPosition().get()); + epos->SetUParameter( point->myU ); + break; + } + case TopAbs_FACE: { + aMeshDS->SetNodeOnFace( node, TopoDS::Face( S )); + SMDS_FacePosition* pos = + dynamic_cast(node->GetPosition().get()); + pos->SetUParameter( point->myUV.X() ); + pos->SetVParameter( point->myUV.Y() ); + break; + } + default: + aMeshDS->SetNodeInVolume( node, TopoDS::Shell( S )); + } } } } - // make that SMESH_subMesh::_computeState = COMPUTE_OK - // so that operations with hypotheses will erase the mesh - // being built - if ( subMesh ) - subMesh->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); } - + // create elements - list >::iterator epIt = myElemPointIDs.begin(); - for ( ; epIt != myElemPointIDs.end(); epIt++ ) + + // shapes and groups myElements are on + vector< int > shapeIDs; + vector< list< SMESHDS_Group* > > groups; + if ( onMeshElements ) + { + shapeIDs.resize( myElements.size() ); + groups.resize( myElements.size() ); + const set& allGroups = aMeshDS->GetGroups(); + set::const_iterator grIt; + for ( int i = 0; i < myElements.size(); i++ ) + { + shapeIDs[ i ] = editor.FindShape( myElements[ i ] ); + for ( grIt = allGroups.begin(); grIt != allGroups.end(); grIt++ ) { + SMESHDS_Group* group = dynamic_cast( *grIt ); + if ( group && group->SMDSGroup().Contains( myElements[ i ] )) + groups[ i ].push_back( group ); + } + } + } + int nbElems = myElemPointIDs.size(); // nb elements in a pattern + + list >::iterator epIt, epEnd; + if ( onMeshElements ) { + epIt = myElemXYZIDs.begin(); + epEnd = myElemXYZIDs.end(); + } + else { + epIt = myElemPointIDs.begin(); + epEnd = myElemPointIDs.end(); + } + for ( int iElem = 0; epIt != epEnd; epIt++, iElem++ ) { list< int > & elemPoints = *epIt; // retrieve nodes @@ -2712,7 +3271,10 @@ bool SMESH_Pattern::MakeMesh(SMESH_Mesh* theMesh) list< int >::iterator iIt = elemPoints.begin(); int nbNodes; for ( nbNodes = 0; iIt != elemPoints.end(); iIt++ ) { - nodes[ nbNodes++ ] = pointNodeMap[ & myPoints[ *iIt ]]; + if ( onMeshElements ) + nodes[ nbNodes++ ] = nodesVector[ *iIt ]; + else + nodes[ nbNodes++ ] = pointNodeMap[ & myPoints[ *iIt ]]; } // add an element const SMDS_MeshElement* elem = 0; @@ -2722,7 +3284,8 @@ bool SMESH_Pattern::MakeMesh(SMESH_Mesh* theMesh) elem = aMeshDS->AddFace( nodes[0], nodes[1], nodes[2] ); break; case 4: elem = aMeshDS->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] ); break; - default:; + default: + ASSERT( nbNodes < 8 ); } } else { @@ -2738,13 +3301,51 @@ bool SMESH_Pattern::MakeMesh(SMESH_Mesh* theMesh) case 8: elem = aMeshDS->AddVolume (nodes[0], nodes[1], nodes[2], nodes[3], nodes[4], nodes[5], nodes[6], nodes[7] ); break; - default:; + default: + ASSERT( nbNodes < 8 ); } } - if ( elem ) + // set element on a shape + if ( elem && onMeshElements ) + { + int elemIndex = iElem / nbElems; + if ( shapeIDs[ elemIndex ] > 0 ) + aMeshDS->SetMeshElementOnShape( elem, shapeIDs[ elemIndex ] ); + // add elem in groups + list< SMESHDS_Group* >::iterator g = groups[ elemIndex ].begin(); + for ( ; g != groups[ elemIndex ].end(); ++g ) + (*g)->SMDSGroup().Add( elem ); + } + if ( elem && !myShape.IsNull() ) aMeshDS->SetMeshElementOnShape( elem, myShape ); } + // make that SMESH_subMesh::_computeState = COMPUTE_OK + // so that operations with hypotheses will erase the mesh being built + + SMESH_subMesh * subMesh; + if ( !myShape.IsNull() ) { + subMesh = theMesh->GetSubMeshContaining( myShape ); + if ( subMesh ) + subMesh->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); + } + if ( onMeshElements ) { + list< int > elemIDs; + for ( int i = 0; i < myElements.size(); i++ ) + { + int shapeID = shapeIDs[ i ]; + if ( shapeID > 0 ) { + TopoDS_Shape S = aMeshDS->IndexToShape( shapeID ); + subMesh = theMesh->GetSubMeshContaining( S ); + if ( subMesh ) + subMesh->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); + } + elemIDs.push_back( myElements[ i ]->GetID() ); + } + // remove refined elements and their nodes + editor.Remove( elemIDs, false ); + } + return setErrorCode( ERR_OK ); } @@ -3026,6 +3627,7 @@ bool SMESH_Pattern::findBoundaryPoints() double edgeLength = 0; list< TPoint* >::iterator pIt = boundary->begin(); getShapePoints( edgeID ).push_back( *pIt ); + getShapePoints( vertexID++ ).push_back( *pIt ); for ( pIt++; pIt != boundary->end(); pIt++) { list< TPoint* > & edgePoints = getShapePoints( edgeID ); @@ -3050,10 +3652,11 @@ bool SMESH_Pattern::findBoundaryPoints() } // begin the next edge treatment edgeLength = 0; - getShapePoints( vertexID++ ).push_back( point ); edgeID++; - if ( point != boundary->front() ) + if ( point != boundary->front() ) { // not the first key-point again getShapePoints( edgeID ).push_back( point ); + getShapePoints( vertexID++ ).push_back( point ); + } } } } @@ -3153,17 +3756,23 @@ bool SMESH_Pattern::setShapeToMesh(const TopoDS_Shape& theShape) //purpose : Return nodes coordinates computed by Apply() method //======================================================================= -bool SMESH_Pattern::GetMappedPoints ( list< const gp_XYZ * > & thePoints ) +bool SMESH_Pattern::GetMappedPoints ( list< const gp_XYZ * > & thePoints ) const { thePoints.clear(); if ( !myIsComputed ) return false; - vector< TPoint >::iterator pVecIt = myPoints.begin(); - for ( ; pVecIt != myPoints.end(); pVecIt++ ) - thePoints.push_back( & (*pVecIt).myXYZ.XYZ() ); - - return ( thePoints.size() > 0 ); + if ( myElements.empty() ) { // applied to shape + vector< TPoint >::const_iterator pVecIt = myPoints.begin(); + for ( ; pVecIt != myPoints.end(); pVecIt++ ) + thePoints.push_back( & (*pVecIt).myXYZ.XYZ() ); + } + else { // applied to mesh elements + vector::const_iterator xyz = myXYZ.begin(); + for ( ; xyz != myXYZ.end(); ++xyz ) + thePoints.push_back( & (*xyz) ); + } + return !thePoints.empty(); } diff --git a/src/SMESH/SMESH_Pattern.hxx b/src/SMESH/SMESH_Pattern.hxx index 9358fae47..0a54cfa71 100644 --- a/src/SMESH/SMESH_Pattern.hxx +++ b/src/SMESH/SMESH_Pattern.hxx @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -35,6 +36,10 @@ #include #include +class SMDS_MeshElement; +class SMDS_MeshFace; +class SMDS_MeshVolume; +class SMDS_MeshNode; class SMESH_Mesh; class TopoDS_Shell; class TopoDS_Vertex; @@ -56,7 +61,7 @@ class SMESH_Pattern { // clear fields bool Load (const char* theFileContents); - // Load a pattern from + // Load a pattern from bool Load (SMESH_Mesh* theMesh, const TopoDS_Face& theFace, @@ -88,7 +93,39 @@ class SMESH_Pattern { // will be mapped into . The // (0,0,1) key-point will be mapped into . - bool GetMappedPoints ( std::list & thePoints ); + bool Apply (const SMDS_MeshFace* theFace, + const int theNodeIndexOnKeyPoint1, + const bool theReverse); + // Compute nodes coordinates applying + // the loaded pattern to . The first key-point + // will be mapped into -th node + + bool Apply (std::set theFaces, + const int theNodeIndexOnKeyPoint1, + const bool theReverse); + // Compute nodes coordinates applying + // the loaded pattern to . The first key-point + // will be mapped into -th node + + bool Apply (const SMDS_MeshVolume* theVolume, + const int theNode000Index, + const int theNode001Index); + // Compute nodes coordinates applying + // the loaded pattern to . The (0,0,0) key-point + // will be mapped into -th node. The + // (0,0,1) key-point will be mapped into -th + // node. + + bool Apply (std::set theVolumes, + const int theNode000Index, + const int theNode001Index); + // Compute nodes coordinates applying + // the loaded pattern to . The (0,0,0) key-point + // will be mapped into -th node. The + // (0,0,1) key-point will be mapped into -th + // node. + + bool GetMappedPoints ( std::list & thePoints ) const; // Return nodes coordinates computed by Apply() method bool MakeMesh(SMESH_Mesh* theMesh); @@ -131,6 +168,8 @@ class SMESH_Pattern { ERR_APPLF_INTERNAL_EEROR, // program error // Apply(volume) ERR_APPLV_BAD_SHAPE, // volume is not a brick of 6 faces + // Apply(mesh_face) + ERR_APPLF_BAD_FACE_GEOM, // bad face geometry // MakeMesh ERR_MAKEM_NOT_COMPUTED // mapping failed }; @@ -152,7 +191,7 @@ class SMESH_Pattern { // GetPoints() and GetMappedPoints() const std::list< std::list< int > >& GetElementPointIDs () const - { return myElemPointIDs; } + { return myElemXYZIDs.empty() ? myElemPointIDs : myElemXYZIDs; } // Return nodal connectivity of the elements of the pattern void DumpPoints() const; @@ -230,7 +269,14 @@ class SMESH_Pattern { // of boundaries; after sorting, edges in the wires are put // in a good order, point UVs on edges are computed and points // are appended to theEdgesPointsList - + + typedef std::set TNodeSet; + void mergePoints (std::map > >& xyzIndGroups, + std::map< int, std::list< std::list< int >* > >& reverseConnectivity); + // Look for coincident points between myXYZs indexed with + // list of each element of xyzIndGroups. Coincident indices + // are merged in myElemXYZIDs using reverseConnectivity. + private: // fields @@ -245,12 +291,21 @@ class SMESH_Pattern { TopoDS_Shape myShape; // all functions assure that shapes are indexed so that first go - // ordered vertices, then ordered edge, then faces and a shell + // ordered vertices, then ordered edge, then faces and maybe a shell TopTools_IndexedMapOfOrientedShape myShapeIDMap; //TopTools_IndexedMapOfShape myShapeIDMap; std::map< int, list< TPoint* > > myShapeIDToPointsMap; - std::list< int > myNbKeyPntInBoundary; //for the 2d case + // for the 2d case: + // nb of key-points in each of pattern boundaries + std::list< int > myNbKeyPntInBoundary; + + // to compute while applying to mesh elements, not to shapes + std::vector myXYZ; + std::list< std::list< int > > myElemXYZIDs; + std::map< int, const SMDS_MeshNode*> myXYZIdToNodeMap; // map id to node of a refined element + std::vector myElements; // refined elements + std::vector myOrderedNodes; }; diff --git a/src/SMESHDS/SMESHDS_Mesh.hxx b/src/SMESHDS/SMESHDS_Mesh.hxx index dece6ab48..459d30848 100644 --- a/src/SMESHDS/SMESHDS_Mesh.hxx +++ b/src/SMESHDS/SMESHDS_Mesh.hxx @@ -42,6 +42,7 @@ #include #include #include +#include //Not portable see http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#5_4 to know more. #ifdef __GNUC__ @@ -178,12 +179,12 @@ public: bool HasMeshElements(const TopoDS_Shape & S); SMESHDS_SubMesh * MeshElements(const TopoDS_Shape & S); SMESHDS_SubMesh * MeshElements(const int Index); - list SubMeshIndices(); + std::list SubMeshIndices(); const std::map& SubMeshes() { return myShapeIndexToSubMesh; } bool HasHypothesis(const TopoDS_Shape & S); - const list& GetHypothesis(const TopoDS_Shape & S) const; + const std::list& GetHypothesis(const TopoDS_Shape & S) const; SMESHDS_Script * GetScript(); void ClearScript(); int ShapeToIndex(const TopoDS_Shape & aShape); @@ -200,7 +201,7 @@ public: void AddGroup (SMESHDS_GroupBase* theGroup) { myGroups.insert(theGroup); } void RemoveGroup (SMESHDS_GroupBase* theGroup) { myGroups.erase(theGroup); } int GetNbGroups() const { return myGroups.size(); } - const set& GetGroups() const { return myGroups; } + const std::set& GetGroups() const { return myGroups; } bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const; @@ -219,8 +220,8 @@ private: int myMeshID; TopoDS_Shape myShape; TopTools_IndexedMapOfShape myIndexToShape; - map myShapeIndexToSubMesh; - set myGroups; + std::map myShapeIndexToSubMesh; + std::set myGroups; SMESHDS_Script* myScript; }; diff --git a/src/SMESHGUI/Makefile.in b/src/SMESHGUI/Makefile.in index e3a137822..bc02829e3 100644 --- a/src/SMESHGUI/Makefile.in +++ b/src/SMESHGUI/Makefile.in @@ -88,6 +88,7 @@ LIB_SRC = SMESHGUI.cxx \ SMESHGUI_SmoothingDlg.cxx \ SMESHGUI_RenumberingDlg.cxx \ SMESHGUI_ExtrusionDlg.cxx \ + SMESHGUI_ExtrusionAlongPathDlg.cxx \ SMESHGUI_RevolutionDlg.cxx \ SMESHGUI_RotationDlg.cxx \ SMESHGUI_TranslationDlg.cxx \ @@ -138,6 +139,7 @@ LIB_MOC = \ SMESHGUI_SmoothingDlg.h \ SMESHGUI_RenumberingDlg.h \ SMESHGUI_ExtrusionDlg.h \ + SMESHGUI_ExtrusionAlongPathDlg.h \ SMESHGUI_RevolutionDlg.h \ SMESHGUI_RotationDlg.h \ SMESHGUI_TranslationDlg.h \ @@ -169,7 +171,7 @@ LIB_SERVER_IDL = #BIN = SMESHBin CPPFLAGS += $(QT_INCLUDES) $(VTK_INCLUDES) $(OGL_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES) \ - $(MED2_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome -I${GEOM_ROOT_DIR}/include/salome \ + -I${KERNEL_ROOT_DIR}/include/salome -I${GEOM_ROOT_DIR}/include/salome \ $(BOOST_CPPFLAGS) CXXFLAGS += -I${KERNEL_ROOT_DIR}/include/salome -I${GEOM_ROOT_DIR}/include/salome diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 78f27d222..ca77a9b2c 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -53,6 +53,7 @@ #include "SMESHGUI_SmoothingDlg.h" #include "SMESHGUI_RenumberingDlg.h" #include "SMESHGUI_ExtrusionDlg.h" +#include "SMESHGUI_ExtrusionAlongPathDlg.h" #include "SMESHGUI_RevolutionDlg.h" #include "SMESHGUI_TranslationDlg.h" #include "SMESHGUI_RotationDlg.h" @@ -140,7 +141,9 @@ namespace{ void ExportMeshToFile(QAD_Desktop * parent, int theCommandID); - void SetViewMode(int theCommandID); + void SetDisplayMode(int theCommandID); + + void SetDisplayEntity(int theCommandID); void Control( int theCommandID ); @@ -153,15 +156,16 @@ namespace{ SMESH::SMESH_Gen_ptr theComponentMesh, int theCommandID) { - QString filter; + QStringList filter; string myExtension; if(theCommandID == 113){ - filter = QObject::tr("MED files (*.med)"); + filter.append(QObject::tr("MED files (*.med)")); + filter.append(QObject::tr("All files (*)")); }else if (theCommandID == 112){ - filter = QObject::tr("IDEAS files (*.unv)"); + filter.append(QObject::tr("IDEAS files (*.unv)")); }else if (theCommandID == 111){ - filter = QObject::tr("DAT files (*.dat)"); + filter.append(QObject::tr("DAT files (*.dat)")); } QString filename = QAD_FileDlg::getFileName(parent, "", @@ -237,9 +241,11 @@ namespace{ SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface(anIObject); if ( !aMesh->_is_nil() ) { QString aFilter, aTitle = QObject::tr("Export mesh"); + QMap aFilterMap; switch ( theCommandID ) { case 122: - aFilter = QObject::tr("MED files (*.med)"); + aFilterMap.insert( QObject::tr("MED 2.1 (*.med)"), SMESH::MED_V2_1 ); + aFilterMap.insert( QObject::tr("MED 2.2 (*.med)"), SMESH::MED_V2_2 ); break; case 121: aFilter = QObject::tr("DAT files (*.dat)"); @@ -261,7 +267,25 @@ namespace{ return; }} - QString aFilename = QAD_FileDlg::getFileName(parent, "", aFilter, aTitle, false); + QString aFilename; + SMESH::MED_VERSION aFormat; + + if ( theCommandID != 122) + aFilename = QAD_FileDlg::getFileName(parent, "", aFilter, aTitle, false); + else + { + QStringList filters; + for ( QMap::const_iterator it = aFilterMap.begin(); it != aFilterMap.end(); ++it ) + filters.push_back( it.key() ); + + QAD_FileDlg* fd = new QAD_FileDlg( parent, false, true, true ); + fd->setCaption( aTitle ); + fd->setFilters( filters ); + fd->exec(); + aFilename = fd->selectedFile(); + aFormat = aFilterMap[fd->selectedFilter()]; + delete fd; + } if ( !aFilename.isEmpty() ) { // Check whether the file already exists and delete it if yes QFile aFile( aFilename ); @@ -270,7 +294,7 @@ namespace{ QAD_WaitCursor wc; switch ( theCommandID ) { case 122: - aMesh->ExportMED( aFilename.latin1(), true ); // currently, automatic groups are always created + aMesh->ExportToMED( aFilename.latin1(), false, aFormat ); // currently, automatic groups are never created break; case 121: aMesh->ExportDAT( aFilename.latin1() ); @@ -286,20 +310,59 @@ namespace{ } } - void SetViewMode(int theCommandID){ + inline void InverseEntityMode(unsigned int& theOutputMode, + unsigned int theMode) + { + bool anIsNotPresent = ~theOutputMode & theMode; + if(anIsNotPresent) + theOutputMode |= theMode; + else + theOutputMode &= ~theMode; + } + + void SetDisplayEntity(int theCommandID){ + SALOME_Selection *Sel = SALOME_Selection::Selection(SMESH::GetActiveStudy()->getSelection()); + if(Sel->IObjectCount() >= 1){ + SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); + for(; It.More(); It.Next()){ + Handle(SALOME_InteractiveObject) IObject = It.Value(); + if(IObject->hasEntry()){ + if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){ + unsigned int aMode = anActor->GetEntityMode(); + switch(theCommandID){ + case 217: + InverseEntityMode(aMode,SMESH_Actor::eEdges); + break; + case 218: + InverseEntityMode(aMode,SMESH_Actor::eFaces); + break; + case 219: + InverseEntityMode(aMode,SMESH_Actor::eVolumes); + break; + case 220: + aMode = SMESH_Actor::eAllEntity; + break; + } + if(aMode) + anActor->SetEntityMode(aMode); + } + } + } + } + } + + void SetDisplayMode(int theCommandID){ SALOME_Selection *Sel = SALOME_Selection::Selection(SMESH::GetActiveStudy()->getSelection()); if(Sel->IObjectCount() >= 1){ switch(theCommandID){ case 1134:{ SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog(); - SMESHGUI_ClippingDlg *aDlg = - new SMESHGUI_ClippingDlg(QAD_Application::getDesktop(),"",false); + new SMESHGUI_ClippingDlg(QAD_Application::getDesktop(),"",false); return; } case 1133:{ SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog(); - SMESHGUI_TransparencyDlg *aDlg = - new SMESHGUI_TransparencyDlg(QAD_Application::getDesktop(),"",false); + new SMESHGUI_TransparencyDlg(QAD_Application::getDesktop(),"",false); return; }} SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); @@ -504,7 +567,11 @@ namespace{ switch ( theCommandID ){ case 6001: aTitle = QObject::tr( "LENGTH_EDGES" ); - aControl = SMESH_Actor::eLengthEdges; + aControl = SMESH_Actor::eLength; + break; + case 6018: + aTitle = QObject::tr( "LENGTH2D_EDGES" ); + aControl = SMESH_Actor::eLength2D; break; case 6002: aTitle = QObject::tr( "FREE_EDGES" ); @@ -518,6 +585,10 @@ namespace{ aTitle = QObject::tr( "MULTI_BORDERS" ); aControl = SMESH_Actor::eMultiConnection; break; + case 6019: + aTitle = QObject::tr( "MULTI2D_BORDERS" ); + aControl = SMESH_Actor::eMultiConnection2D; + break; case 6011: aTitle = QObject::tr( "AREA_ELEMENTS" ); aControl = SMESH_Actor::eArea; @@ -530,6 +601,10 @@ namespace{ aTitle = QObject::tr( "ASPECTRATIO_ELEMENTS" ); aControl = SMESH_Actor::eAspectRatio; break; + case 6017: + aTitle = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" ); + aControl = SMESH_Actor::eAspectRatio3D; + break; case 6014: aTitle = QObject::tr( "MINIMUMANGLE_ELEMENTS" ); aControl = SMESH_Actor::eMinimumAngle; @@ -1029,14 +1104,22 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) case 1134: // Clipping case 1133: // Tranparency case 1132: // Colors / Size - case 215: - case 213: - case 212: - case 211: - { - ::SetViewMode(theCommandID); - break; - } + + // Display Mode + case 215: // Nodes + case 213: // Nodes + case 212: // Nodes + case 211: // Nodes + ::SetDisplayMode(theCommandID); + break; + + // Display Entity + case 217: // Edges + case 218: // Faces + case 219: // Volumes + case 220: // All Entity + ::SetDisplayEntity(theCommandID); + break; case 214: // UPDATE { @@ -1076,7 +1159,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg(parent, "", Sel); + new SMESHGUI_NodesDlg(parent, "", Sel); } else { QAD_MessageBox::warn1(QAD_Application::getDesktop(), @@ -1092,7 +1175,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { EmitSignalDeactivateDialog(); - SMESHGUI_FilterDlg *aDlg = new SMESHGUI_FilterDlg( parent, SMESH::EDGE ); + new SMESHGUI_FilterDlg( parent, SMESH::EDGE ); } break; } @@ -1108,7 +1191,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if(checkLock(aStudy)) break; SALOME_Selection *Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); - SMESHGUI_MoveNodesDlg *aDlg = new SMESHGUI_MoveNodesDlg( parent, Sel ); + new SMESHGUI_MoveNodesDlg( parent, Sel ); break; } @@ -1216,7 +1299,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_AddSubMeshDlg *aDlg = new SMESHGUI_AddSubMeshDlg(parent, "", Sel); + new SMESHGUI_AddSubMeshDlg(parent, "", Sel); } else { QAD_MessageBox::warn1(QAD_Application::getDesktop(), @@ -1231,7 +1314,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if(checkLock(aStudy)) break; EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg(parent, "", Sel); + new SMESHGUI_InitMeshDlg(parent, "", Sel); break; } @@ -1240,7 +1323,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if(checkLock(aStudy)) break; EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel); + new SMESHGUI_EditHypothesesDlg(parent, "", Sel); break; } @@ -1249,7 +1332,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if(checkLock(aStudy)) break; EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel); + new SMESHGUI_EditHypothesesDlg(parent, "", Sel); break; } @@ -1258,7 +1341,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if(checkLock(aStudy)) break; EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel); + new SMESHGUI_EditHypothesesDlg(parent, "", Sel); break; } @@ -1331,7 +1414,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_SmoothingDlg *aDlg = new SMESHGUI_SmoothingDlg(parent, "", Sel); + new SMESHGUI_SmoothingDlg(parent, "", Sel); } else { QAD_MessageBox::warn1(QAD_Application::getDesktop(), @@ -1346,7 +1429,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_ExtrusionDlg *aDlg = new SMESHGUI_ExtrusionDlg(parent, "", Sel); + new SMESHGUI_ExtrusionDlg(parent, "", Sel); } else { QAD_MessageBox::warn1(QAD_Application::getDesktop(), @@ -1361,7 +1444,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_RevolutionDlg *aDlg = new SMESHGUI_RevolutionDlg(parent, "", Sel); + new SMESHGUI_RevolutionDlg(parent, "", Sel); } else { QAD_MessageBox::warn1(QAD_Application::getDesktop(), @@ -1388,6 +1471,21 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) } break; } + case 416: // Extrusion along a path + { + if(checkLock(aStudy)) break; + if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { + EmitSignalDeactivateDialog(); + SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); + new SMESHGUI_ExtrusionAlongPathDlg(parent, Sel); + } + else { + QAD_MessageBox::warn1(QAD_Application::getDesktop(), + tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"), + tr("SMESH_BUT_OK")); + } + break; + } case 801: // CREATE GROUP { if(checkLock(aStudy)) break; @@ -1544,7 +1642,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) for ( ; It.More(); It.Next() ) { Sel->ClearIObjects(); Sel->AddIObject( It.Value() ); - SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg(parent, "", false); + new SMESHGUI_MeshInfosDlg(parent, "", false); } // restore selection Sel->ClearIObjects(); @@ -1552,7 +1650,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) Sel->AddIObject( It.Value() ); } else - SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg(parent, "", false); + new SMESHGUI_MeshInfosDlg(parent, "", false); break; } @@ -1567,7 +1665,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) for ( ; It.More(); It.Next() ) { Sel->ClearIObjects(); Sel->AddIObject( It.Value() ); - SMESHGUI_StandardMeshInfosDlg *aDlg = new SMESHGUI_StandardMeshInfosDlg(parent, "", false); + new SMESHGUI_StandardMeshInfosDlg(parent, "", false); } // restore selection Sel->ClearIObjects(); @@ -1575,7 +1673,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) Sel->AddIObject( It.Value() ); } else - SMESHGUI_StandardMeshInfosDlg *aDlg = new SMESHGUI_StandardMeshInfosDlg(parent, "", false); + new SMESHGUI_StandardMeshInfosDlg(parent, "", false); break; } @@ -1605,12 +1703,23 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) break; } - case 1007: + case 10070: { ( new SMESHGUI_PrecisionDlg( parent ) )->exec(); break; } + case 10071: + { + parent->menuBar()->setItemChecked(10071, !parent->menuBar()->isItemChecked(10071)); + if (parent->menuBar()->isItemChecked(10071)) { + QAD_CONFIG->addSetting("SMESH:DispayEntity","true"); + } + else { + QAD_CONFIG->addSetting("SMESH:DispayEntity","false"); + } + break; + } case 1006: { SMESHGUI_Preferences_SelectionDlg* aDlg = @@ -1825,8 +1934,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) type = SMDSAbs_Volume; nbNodes = 8; break; default:; } - SMESHGUI_AddMeshElementDlg *aDlg = - new SMESHGUI_AddMeshElementDlg(parent, "", Sel, type, nbNodes); + new SMESHGUI_AddMeshElementDlg(parent, "", Sel, type, nbNodes); } else { QAD_MessageBox::warn1(QAD_Application::getDesktop(), @@ -1842,7 +1950,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_RemoveNodesDlg *aDlg = new SMESHGUI_RemoveNodesDlg(parent, "", Sel); + new SMESHGUI_RemoveNodesDlg(parent, "", Sel); } else { QAD_MessageBox::warn1(QAD_Application::getDesktop(), @@ -1857,7 +1965,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_RemoveElementsDlg *aDlg = new SMESHGUI_RemoveElementsDlg(parent, "", Sel); + new SMESHGUI_RemoveElementsDlg(parent, "", Sel); } else { @@ -1873,7 +1981,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_RenumberingDlg *aDlg = new SMESHGUI_RenumberingDlg(parent, "", Sel, 0); + new SMESHGUI_RenumberingDlg(parent, "", Sel, 0); } else { @@ -1889,7 +1997,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_RenumberingDlg *aDlg = new SMESHGUI_RenumberingDlg(parent, "", Sel, 1); + new SMESHGUI_RenumberingDlg(parent, "", Sel, 1); } else { @@ -1905,7 +2013,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_TranslationDlg *aDlg = new SMESHGUI_TranslationDlg(parent, "", Sel); + new SMESHGUI_TranslationDlg(parent, "", Sel); } else { QAD_MessageBox::warn1(QAD_Application::getDesktop(), @@ -1920,7 +2028,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_RotationDlg *aDlg = new SMESHGUI_RotationDlg(parent, "", Sel); + new SMESHGUI_RotationDlg(parent, "", Sel); } else { QAD_MessageBox::warn1(QAD_Application::getDesktop(), @@ -1935,7 +2043,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_SymmetryDlg *aDlg = new SMESHGUI_SymmetryDlg(parent, "", Sel); + new SMESHGUI_SymmetryDlg(parent, "", Sel); } else { QAD_MessageBox::warn1(QAD_Application::getDesktop(), @@ -1950,7 +2058,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_SewingDlg *aDlg = new SMESHGUI_SewingDlg(parent, "", Sel); + new SMESHGUI_SewingDlg(parent, "", Sel); } else { QAD_MessageBox::warn1(QAD_Application::getDesktop(), @@ -1965,7 +2073,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { EmitSignalDeactivateDialog(); SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection()); - SMESHGUI_MergeNodesDlg *aDlg = new SMESHGUI_MergeNodesDlg(parent, "", Sel); + new SMESHGUI_MergeNodesDlg(parent, "", Sel); } else { QAD_MessageBox::warn1(QAD_Application::getDesktop(), @@ -1980,16 +2088,14 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) { if(checkLock(aStudy)) break; EmitSignalDeactivateDialog(); - SMESHGUI_CreateHypothesesDlg *aDlg = - new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, false); + new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, false); break; } case 5010: // ALGO { if(checkLock(aStudy)) break; EmitSignalDeactivateDialog(); - SMESHGUI_CreateHypothesesDlg *aDlg = - new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, true); + new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, true); break; } @@ -2007,13 +2113,16 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) } break; - case 6016: // CONTROLS + case 6017: // CONTROLS + case 6016: case 6015: case 6014: case 6013: case 6012: case 6011: case 6001: + case 6018: + case 6019: case 6002: case 6003: case 6004: @@ -2198,6 +2307,12 @@ bool SMESHGUI::SetSettings(QAD_Desktop * parent) myAutomaticUpdate = false; } + QString anIsDisplayEntity = QAD_CONFIG->getSetting("SMESH:DispayEntity"); + if(anIsDisplayEntity.compare("true") == 0) + parent->menuBar()->setItemChecked(10071,true); + else + parent->menuBar()->setItemChecked(10071,false); + /* Selection */ SMESH::UpdateSelectionProp(); @@ -2316,29 +2431,30 @@ bool SMESHGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString if ( !aGeomGroup->_is_nil() ) // group linked on geometry popup->removeItem( 803 ); // EDIT GROUP - SMESH_Actor* ac = SMESH::FindActorByEntry(IObject->getEntry()); + SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry()); // if object has actor - if ( ac && studyFrame->getTypeView() == VIEW_VTK ) { + if ( anActor && studyFrame->getTypeView() == VIEW_VTK ) { VTKViewer_RenderWindowInteractor* myRenderInter = SMESH::GetCurrentVtkView()->getRWInteractor(); if ( myRenderInter->isVisible( IObject ) ) { popup->removeItem( QAD_Display_Popup_ID ); - popup->setItemChecked( 9010, ac->GetPointsLabeled() ); // Numbering / Display Nodes # - popup->setItemChecked( 9011, ac->GetCellsLabeled() ); // Numbering / Display Elements # - TVisualObjPtr aVisualObj = ac->GetObject(); - int aNbEdges = aVisualObj->GetNbEntities(SMESH::EDGE); - int aNbFaces = aVisualObj->GetNbEntities(SMESH::FACE); - int aNbVolumes = aVisualObj->GetNbEntities(SMESH::VOLUME); + popup->setItemChecked( 9010, anActor->GetPointsLabeled() ); // Numbering / Display Nodes # + popup->setItemChecked( 9011, anActor->GetCellsLabeled() ); // Numbering / Display Elements # + TVisualObjPtr aVisualObj = anActor->GetObject(); + int aNbEdges = aVisualObj->GetNbEntities(SMDSAbs_Edge); + int aNbFaces = aVisualObj->GetNbEntities(SMDSAbs_Face); + int aNbVolumes = aVisualObj->GetNbEntities(SMDSAbs_Volume); + QMenuItem* mi = popup->findItem( 1131 ); if ( mi && mi->popup() ) { - int prType = ac->GetRepresentation(); + int prType = anActor->GetRepresentation(); // Display Mode / Wireframe - if(!aNbFaces && !aNbVolumes && !aNbEdges){ + if(aNbVolumes == 0 && aNbFaces == 0 && aNbEdges == 0){ mi->popup()->removeItem( 211 ); }else{ mi->popup()->setItemChecked( 211, prType == SMESH_Actor::eEdge ); } // Display Mode / Shading - if(!aNbFaces && !aNbVolumes){ + if(aNbFaces == 0 && aNbVolumes == 0){ mi->popup()->removeItem( 212 ); }else{ mi->popup()->setItemChecked( 212, prType == SMESH_Actor::eSurface ); @@ -2346,18 +2462,62 @@ bool SMESHGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString // Display Mode / Points mi->popup()->setItemChecked( 215, prType == SMESH_Actor::ePoint ); // Display Mode / Shrink - bool isShrunk = ac->IsShrunk(); - bool isShrunkable = ac->IsShrunkable(); + bool isShrunk = anActor->IsShrunk(); + bool isShrunkable = anActor->IsShrunkable(); mi->popup()->setItemChecked( 213, isShrunk ); mi->popup()->setItemEnabled( 213, prType != SMESH_Actor::ePoint && isShrunkable); } - // Scalar Bar + + // Display Entity + mi = popup->findItem( 1135 ); + int aIsSomething=0; + if (aNbVolumes>0) aIsSomething++; + if (aNbFaces>0) aIsSomething++; + if (aNbEdges>0) aIsSomething++; + if ( mi && (aIsSomething <= 1)){ + popup->removeItem(1135); + }else if ( mi && mi->popup() ) { + QPopupMenu* aPopup = mi->popup(); + unsigned int aMode = anActor->GetEntityMode(); + + bool aIsVolumesMode = aMode & SMESH_Actor::eVolumes; + bool aIsFacesMode = aMode & SMESH_Actor::eFaces; + bool aIsEdgesMode = aMode & SMESH_Actor::eEdges; + + if(aNbVolumes == 0) + aPopup->removeItem( 219 ); + else + aPopup->setItemChecked( 219, aIsVolumesMode ); + + if(aNbFaces == 0) + aPopup->removeItem( 218 ); + else + aPopup->setItemChecked( 218, aIsFacesMode ); + + + if(aNbEdges == 0) + aPopup->removeItem( 217 ); + else + aPopup->setItemChecked( 217, aIsEdgesMode ); + + + bool aIsRemove = (aNbVolumes == 0 || aIsVolumesMode); + aIsRemove &= (aNbFaces == 0 || aIsFacesMode); + aIsRemove &= (aNbEdges == 0 || aIsEdgesMode); + + if(aIsRemove) + aPopup->removeItem( 220 ); + } + + // Controls mi = popup->findItem( 2000 ); if ( mi && mi->popup() ) { - SMESH_Actor::eControl cMode = ac->GetControlMode(); + SMESH_Actor::eControl cMode = anActor->GetControlMode(); switch ( cMode ) { - case SMESH_Actor::eLengthEdges: + case SMESH_Actor::eLength: mi->popup()->setItemChecked( 6001, true ); break; + case SMESH_Actor::eLength2D: + mi->popup()->setItemChecked( 6018, true ); break; case SMESH_Actor::eFreeEdges: mi->popup()->setItemChecked( 6002, true ); mi->popup()->removeItem( 201 ); @@ -2368,12 +2528,16 @@ bool SMESHGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString break; case SMESH_Actor::eMultiConnection: mi->popup()->setItemChecked( 6004, true ); break; + case SMESH_Actor::eMultiConnection2D: + mi->popup()->setItemChecked( 6019, true ); break; case SMESH_Actor::eArea: mi->popup()->setItemChecked( 6011, true ); break; case SMESH_Actor::eTaper: mi->popup()->setItemChecked( 6012, true ); break; case SMESH_Actor::eAspectRatio: mi->popup()->setItemChecked( 6013, true ); break; + case SMESH_Actor::eAspectRatio3D: + mi->popup()->setItemChecked( 6017, true ); break; case SMESH_Actor::eMinimumAngle: mi->popup()->setItemChecked( 6014, true ); break; case SMESH_Actor::eWarping: @@ -2386,13 +2550,14 @@ bool SMESHGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString mi->popup()->removeItem( 201 ); break; } - TVisualObjPtr aVisualObj = ac->GetObject(); - if(!aNbEdges){ + TVisualObjPtr aVisualObj = anActor->GetObject(); + if(aNbEdges == 0){ mi->popup()->removeItem( 6001 ); mi->popup()->removeItem( 6003 ); mi->popup()->removeItem( 6004 ); } - if(!aNbFaces){ + if(aNbFaces == 0){ + mi->popup()->removeItem( 6018 ); mi->popup()->removeItem( 6002 ); mi->popup()->removeItem( 6011 ); mi->popup()->removeItem( 6012 ); @@ -2400,8 +2565,12 @@ bool SMESHGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString mi->popup()->removeItem( 6014 ); mi->popup()->removeItem( 6015 ); mi->popup()->removeItem( 6016 ); + mi->popup()->removeItem( 6019 ); + } + if(aNbVolumes == 0){ + mi->popup()->removeItem( 6017 ); } - if(!aNbFaces && !aNbEdges) + if(aNbFaces == 0 && aNbEdges == 0 && aNbVolumes == 0) popup->removeItem( 2000 ); // Scalar Bar } } diff --git a/src/SMESHGUI/SMESHGUI_ClippingDlg.cxx b/src/SMESHGUI/SMESHGUI_ClippingDlg.cxx index d98228dde..567d567f3 100644 --- a/src/SMESHGUI/SMESHGUI_ClippingDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_ClippingDlg.cxx @@ -63,6 +63,11 @@ #include "SALOME_InteractiveObject.hxx" #include "SMESH_ActorUtils.h" +#include "VTKViewer_ViewFrame.h" +#include "VTKViewer_RenderWindow.h" + +#include + using namespace std; @@ -151,8 +156,6 @@ protected: myActor->SetInfinitive(true); myActor->SetMapper( myMapper ); - static float anOpacity = 0.75; - vtkProperty* aProp = vtkProperty::New(); float anRGB[3]; anRGB[0] = SMESH::GetFloat("SMESH:SettingsFillColorRed", 0)/255.; @@ -375,9 +378,8 @@ SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( QWidget* parent, SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg() { // no need to delete child widgets, Qt does it all for us - //cout<<"SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg\n"; std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false)); - SMESH::GetCurrentVtkView()->Repaint(); + SMESH::RenderViewFrame(SMESH::GetCurrentVtkView()); } @@ -406,10 +408,8 @@ void SMESHGUI_ClippingDlg::ClickOnApply() aCollection->AddItem(anOrientedPlane); anOrientedPlane->Delete(); } - - myActor->SetVisibility(myActor->GetVisibility()); - - SMESH::GetCurrentVtkView()->Repaint(); + + SMESH::RenderViewFrame(SMESH::GetCurrentVtkView()); } } @@ -466,7 +466,7 @@ void SMESHGUI_ClippingDlg::onSelectionChanged() } } Sinchronize(); - SMESH::GetCurrentVtkView()->Repaint(); + SMESH::RenderViewFrame(SMESH::GetCurrentVtkView()); } @@ -484,8 +484,7 @@ void SMESHGUI_ClippingDlg::onSelectPlane(int theIndex) // Orientation SMESH::Orientation anOrientation = aPlane->GetOrientation(); - // Distance and Rotations - float aDistance; + // Rotations double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]}; // Set plane parameters in the dialog @@ -550,7 +549,7 @@ void SMESHGUI_ClippingDlg::ClickOnDelete() ClickOnApply(); Sinchronize(); - SMESH::GetCurrentVtkView()->Repaint(); + SMESH::RenderViewFrame(SMESH::GetCurrentVtkView()); } @@ -702,7 +701,6 @@ void SMESHGUI_ClippingDlg::SetCurrentPlaneParam() myActor->SetPlaneParam(aNormal, getDistance(), aPlane); - float* anOrig = aPlane->GetOrigin(); vtkDataSet* aDataSet = myActor->GetInput(); float *aPnt = aDataSet->GetCenter(); @@ -746,11 +744,11 @@ void SMESHGUI_ClippingDlg::SetCurrentPlaneParam() if(AutoApplyCheckBox->isChecked()) ClickOnApply(); - SMESH::GetCurrentVtkView()->Repaint(); + SMESH::RenderViewFrame(SMESH::GetCurrentVtkView()); } void SMESHGUI_ClippingDlg::OnPreviewToggle(bool theIsToggled){ std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(theIsToggled)); - SMESH::GetCurrentVtkView()->Repaint(); + SMESH::RenderViewFrame(SMESH::GetCurrentVtkView()); } diff --git a/src/SMESHGUI/SMESHGUI_ExtrusionAlongPathDlg.cxx b/src/SMESHGUI/SMESHGUI_ExtrusionAlongPathDlg.cxx new file mode 100644 index 000000000..d99f0ad20 --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_ExtrusionAlongPathDlg.cxx @@ -0,0 +1,1127 @@ +// SMESH SMESHGUI : GUI for SMESH component +// +// 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 : SMESHGUI_ExtrusionAlongPathDlg.cxx +// Author : Vadim SANDLER +// Module : SMESH +// $Header: + +#include "SMESHGUI_ExtrusionAlongPathDlg.h" +#include "SMESHGUI.h" +#include "SMESHGUI_SpinBox.h" +#include "SMESHGUI_Utils.h" +#include "SMESHGUI_VTKUtils.h" +#include "SMESHGUI_MeshUtils.h" +#include "SMESHGUI_IdValidator.h" +#include "SMESH_Actor.h" +#include "SMESH_NumberFilter.hxx" +#include "SMDS_Mesh.hxx" +#include "GEOM_ShapeTypeFilter.hxx" +#include "GEOMBase.h" + +#include "QAD_Application.h" +#include "QAD_WaitCursor.h" +#include "QAD_Desktop.h" +#include "QAD_MessageBox.h" +#include "utilities.h" + +#include +#include +#include +#include +#include + +// QT Includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// IDL Headers +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SMESH_Group) + +using namespace std; + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::SMESHGUI_ExtrusionAlongPathDlg() +// purpose : constructor +//================================================================================= +SMESHGUI_ExtrusionAlongPathDlg::SMESHGUI_ExtrusionAlongPathDlg( QWidget* parent, SALOME_Selection* Sel, bool modal ) + : QDialog( parent, "SMESHGUI_ExtrusionAlongPathDlg", modal, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose ) +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::SMESHGUI_ExtrusionAlongPathDlg"); + myType = -1; + QPixmap edgeImage ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_DLG_EDGE" ) ) ); + QPixmap faceImage ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_DLG_TRIANGLE" ) ) ); + QPixmap selectImage( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) ); + QPixmap addImage ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_APPEND" ) ) ); + QPixmap removeImage( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_REMOVE" ) ) ); + + setCaption( tr( "EXTRUSION_ALONG_PATH" ) ); + setSizeGripEnabled( TRUE ); + + QGridLayout* topLayout = new QGridLayout( this ); + topLayout->setSpacing( 6 ); topLayout->setMargin( 11 ); + + /***************************************************************/ + // Elements type group box (1d / 2d elements) + ElementsTypeGrp = new QButtonGroup( tr( "SMESH_EXTRUSION" ), this ); + ElementsTypeGrp->setColumnLayout( 0, Qt::Vertical ); + ElementsTypeGrp->layout()->setSpacing( 0 ); ElementsTypeGrp->layout()->setMargin( 0 ); + QGridLayout* ElementsTypeGrpLayout = new QGridLayout( ElementsTypeGrp->layout() ); + ElementsTypeGrpLayout->setAlignment( Qt::AlignTop ); + ElementsTypeGrpLayout->setSpacing( 6 ); ElementsTypeGrpLayout->setMargin( 11 ); + + Elements1dRB = new QRadioButton( ElementsTypeGrp ); + Elements1dRB->setPixmap( edgeImage ); + Elements2dRB = new QRadioButton( ElementsTypeGrp ); + Elements2dRB->setPixmap( faceImage ); + Elements1dRB->setChecked( true ); + + // layouting + ElementsTypeGrpLayout->addWidget( Elements1dRB, 0, 0 ); + ElementsTypeGrpLayout->addWidget( Elements2dRB, 0, 2 ); + + /***************************************************************/ + // Arguments group box + ArgumentsGrp = new QGroupBox( tr( "EXTRUSION_1D" ), this ); + ArgumentsGrp->setColumnLayout( 0, Qt::Vertical ); + ArgumentsGrp->layout()->setSpacing( 0 ); ArgumentsGrp->layout()->setMargin( 0 ); + QGridLayout* ArgumentsGrpLayout = new QGridLayout( ArgumentsGrp->layout() ); + ArgumentsGrpLayout->setAlignment( Qt::AlignTop ); + ArgumentsGrpLayout->setSpacing( 6 ); ArgumentsGrpLayout->setMargin( 11 ); + + // Controls for elements selection + ElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), ArgumentsGrp ); + + SelectElementsButton = new QToolButton( ArgumentsGrp ); + SelectElementsButton->setPixmap( selectImage ); + + ElementsLineEdit = new QLineEdit( ArgumentsGrp ); + ElementsLineEdit->setValidator( new SMESHGUI_IdValidator( this ) ); + + // Controls for the whole mesh selection + MeshCheck = new QCheckBox( tr( "SMESH_SELECT_WHOLE_MESH" ), ArgumentsGrp ); + + // Controls for path selection + PathGrp = new QGroupBox( tr( "SMESH_PATH" ), ArgumentsGrp ); + PathGrp->setColumnLayout( 0, Qt::Vertical ); + PathGrp->layout()->setSpacing( 0 ); PathGrp->layout()->setMargin( 0 ); + QGridLayout* PathGrpLayout = new QGridLayout( PathGrp->layout() ); + PathGrpLayout->setAlignment( Qt::AlignTop ); + PathGrpLayout->setSpacing( 6 ); PathGrpLayout->setMargin( 11 ); + + // Controls for path mesh selection + PathMeshLab = new QLabel( tr( "SMESH_PATH_MESH" ), PathGrp ); + + SelectPathMeshButton = new QToolButton( PathGrp ); + SelectPathMeshButton->setPixmap( selectImage ); + + PathMeshLineEdit = new QLineEdit( PathGrp ); + PathMeshLineEdit->setReadOnly( true ); + + // Controls for path shape selection + PathShapeLab = new QLabel( tr( "SMESH_PATH_SHAPE" ), PathGrp ); + + SelectPathShapeButton = new QToolButton( PathGrp ); + SelectPathShapeButton->setPixmap( selectImage ); + + PathShapeLineEdit = new QLineEdit( PathGrp ); + PathShapeLineEdit->setReadOnly( true ); + + // Controls for path starting point selection + StartPointLab = new QLabel( tr( "SMESH_PATH_START" ), PathGrp ); + + SelectStartPointButton = new QToolButton( PathGrp ); + SelectStartPointButton->setPixmap( selectImage ); + + StartPointLineEdit = new QLineEdit( PathGrp ); + StartPointLineEdit->setValidator( new QIntValidator( this ) ); + + // layouting + PathGrpLayout->addWidget( PathMeshLab, 0, 0 ); + PathGrpLayout->addWidget( SelectPathMeshButton, 0, 1 ); + PathGrpLayout->addWidget( PathMeshLineEdit, 0, 2 ); + PathGrpLayout->addWidget( PathShapeLab, 1, 0 ); + PathGrpLayout->addWidget( SelectPathShapeButton, 1, 1 ); + PathGrpLayout->addWidget( PathShapeLineEdit, 1, 2 ); + PathGrpLayout->addWidget( StartPointLab, 2, 0 ); + PathGrpLayout->addWidget( SelectStartPointButton, 2, 1 ); + PathGrpLayout->addWidget( StartPointLineEdit, 2, 2 ); + + // Controls for angles defining + AnglesCheck = new QCheckBox( tr( "SMESH_USE_ANGLES" ), ArgumentsGrp ); + + AnglesGrp = new QGroupBox( tr( "SMESH_ANGLES" ), ArgumentsGrp ); + AnglesGrp->setColumnLayout( 0, Qt::Vertical ); + AnglesGrp->layout()->setSpacing( 0 ); AnglesGrp->layout()->setMargin( 0 ); + QGridLayout* AnglesGrpLayout = new QGridLayout( AnglesGrp->layout() ); + AnglesGrpLayout->setAlignment( Qt::AlignTop ); + AnglesGrpLayout->setSpacing( 6 ); AnglesGrpLayout->setMargin( 11 ); + + AnglesList = new QListBox( AnglesGrp ); + AnglesList->setSelectionMode( QListBox::Extended ); + + AddAngleButton = new QToolButton( AnglesGrp ); + AddAngleButton->setPixmap( addImage ); + + RemoveAngleButton = new QToolButton( AnglesGrp ); + RemoveAngleButton->setPixmap( removeImage ); + + AngleSpin = new SMESHGUI_SpinBox( AnglesGrp ); + + // layouting + QVBoxLayout* bLayout = new QVBoxLayout(); + bLayout->addWidget( AddAngleButton ); + bLayout->addSpacing( 6 ); + bLayout->addWidget( RemoveAngleButton ); + bLayout->addStretch(); + AnglesGrpLayout->addMultiCellWidget( AnglesList, 0, 1, 0, 0 ); + AnglesGrpLayout->addMultiCellLayout( bLayout, 0, 1, 1, 1 ); + AnglesGrpLayout->addWidget( AngleSpin, 0, 2 ); + AnglesGrpLayout->setRowStretch( 1, 10 ); + + // Controls for base point defining + BasePointCheck = new QCheckBox( tr( "SMESH_USE_BASE_POINT" ), ArgumentsGrp ); + + BasePointGrp = new QGroupBox( tr( "SMESH_BASE_POINT" ), ArgumentsGrp ); + BasePointGrp->setColumnLayout( 0, Qt::Vertical ); + BasePointGrp->layout()->setSpacing( 0 ); BasePointGrp->layout()->setMargin( 0 ); + QGridLayout* BasePointGrpLayout = new QGridLayout( BasePointGrp->layout() ); + BasePointGrpLayout->setAlignment( Qt::AlignTop ); + BasePointGrpLayout->setSpacing( 6 ); BasePointGrpLayout->setMargin( 11 ); + + SelectBasePointButton = new QToolButton( BasePointGrp ); + SelectBasePointButton->setPixmap( selectImage ); + + XLab = new QLabel( tr( "SMESH_X" ), BasePointGrp ); + XSpin = new SMESHGUI_SpinBox( BasePointGrp ); + YLab = new QLabel( tr( "SMESH_Y" ), BasePointGrp ); + YSpin = new SMESHGUI_SpinBox( BasePointGrp ); + ZLab = new QLabel( tr( "SMESH_Z" ), BasePointGrp ); + ZSpin = new SMESHGUI_SpinBox( BasePointGrp ); + + // layouting + BasePointGrpLayout->addWidget( SelectBasePointButton, 0, 0 ); + BasePointGrpLayout->addWidget( XLab, 0, 1 ); + BasePointGrpLayout->addWidget( XSpin, 0, 2 ); + BasePointGrpLayout->addWidget( YLab, 0, 3 ); + BasePointGrpLayout->addWidget( YSpin, 0, 4 ); + BasePointGrpLayout->addWidget( ZLab, 0, 5 ); + BasePointGrpLayout->addWidget( ZSpin, 0, 6 ); + + // layouting + ArgumentsGrpLayout->addWidget( ElementsLab, 0, 0 ); + ArgumentsGrpLayout->addWidget( SelectElementsButton, 0, 1 ); + ArgumentsGrpLayout->addWidget( ElementsLineEdit, 0, 2 ); + ArgumentsGrpLayout->addMultiCellWidget( MeshCheck, 1, 1, 0, 2 ); + ArgumentsGrpLayout->addMultiCellWidget( PathGrp, 2, 2, 0, 2 ); + ArgumentsGrpLayout->addWidget( AnglesCheck, 3, 0 ); + ArgumentsGrpLayout->addMultiCellWidget( AnglesGrp, 3, 4, 1, 2 ); + ArgumentsGrpLayout->addWidget( BasePointCheck, 5, 0 ); + ArgumentsGrpLayout->addMultiCellWidget( BasePointGrp, 5, 6, 1, 2 ); + ArgumentsGrpLayout->setRowStretch( 4, 10 ); + + /***************************************************************/ + // common buttons group box + ButtonsGrp = new QGroupBox( this ); + ButtonsGrp->setColumnLayout( 0, Qt::Vertical ); + ButtonsGrp->layout()->setSpacing( 0 ); ButtonsGrp->layout()->setMargin( 0 ); + QGridLayout* ButtonsGrpLayout = new QGridLayout( ButtonsGrp->layout() ); + ButtonsGrpLayout->setAlignment( Qt::AlignTop ); + ButtonsGrpLayout->setSpacing( 6 ); ButtonsGrpLayout->setMargin( 11 ); + + OkButton = new QPushButton( tr( "SMESH_BUT_OK" ), ButtonsGrp ); + OkButton->setAutoDefault( true ); + OkButton->setDefault( true ); + + ApplyButton = new QPushButton( tr( "SMESH_BUT_APPLY" ), ButtonsGrp ); + ApplyButton->setAutoDefault( true ); + + CloseButton = new QPushButton( tr( "SMESH_BUT_CLOSE" ), ButtonsGrp ); + CloseButton->setAutoDefault( true ); + + // layouting + ButtonsGrpLayout->addWidget( OkButton, 0, 0 ); + ButtonsGrpLayout->addWidget( ApplyButton, 0, 1 ); + ButtonsGrpLayout->addWidget( CloseButton, 0, 3 ); + ButtonsGrpLayout->addColSpacing( 2, 10 ); + ButtonsGrpLayout->setColStretch( 2, 10 ); + + /***************************************************************/ + // layouting + topLayout->addWidget( ElementsTypeGrp, 0, 0 ); + topLayout->addWidget( ArgumentsGrp, 1, 0 ); + topLayout->addWidget( ButtonsGrp, 2, 0 ); + + /***************************************************************/ + // Initialisations + XSpin->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 ); + YSpin->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 ); + ZSpin->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 ); + AngleSpin->RangeStepAndValidator( -999999.999, +999999.999, 5.0, 3 ); + + mySelection = Sel; + mySMESHGUI = SMESHGUI::GetSMESHGUI() ; + mySMESHGUI->SetActiveDialogBox( this ) ; + + // Costruction of the logical filter for the elements: mesh/sub-mesh/group + SMESH_ListOfFilter aListOfFilters; + Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH ); + if ( !aMeshOrSubMeshFilter.IsNull() ) + aListOfFilters.Append( aMeshOrSubMeshFilter ); + Handle(SMESH_TypeFilter) aSmeshGroupFilter = new SMESH_TypeFilter( GROUP ); + if ( !aSmeshGroupFilter.IsNull() ) + aListOfFilters.Append( aSmeshGroupFilter ); + + myElementsFilter = new SMESH_LogicalFilter( aListOfFilters, SMESH_LogicalFilter::LO_OR ); + + myPathMeshFilter = new SMESH_TypeFilter( MESH ); + + Init(); + + /***************************************************************/ + // signals-slots connections + connect( OkButton, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); + connect( CloseButton, SIGNAL( clicked() ), this, SLOT( reject() ) ) ; + connect( ApplyButton, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); + + connect( AddAngleButton, SIGNAL( clicked() ), this, SLOT( OnAngleAdded() ) ); + connect( RemoveAngleButton, SIGNAL( clicked() ), this, SLOT( OnAngleRemoved() ) ); + + connect( ElementsTypeGrp, SIGNAL( clicked( int ) ), SLOT( TypeChanged( int ) ) ); + + connect( SelectElementsButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ; + connect( SelectPathMeshButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ; + connect( SelectPathShapeButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ; + connect( SelectStartPointButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ; + connect( SelectBasePointButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ; + + connect( mySMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ; + connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( reject() ) ) ; + + connect( ElementsLineEdit, SIGNAL( textChanged( const QString& ) ), + SLOT( onTextChange( const QString& ) ) ); + connect( StartPointLineEdit, SIGNAL( textChanged( const QString& ) ), + SLOT( onTextChange( const QString& ) ) ); + + connect( MeshCheck, SIGNAL( toggled( bool ) ), SLOT( onSelectMesh() ) ); + connect( AnglesCheck, SIGNAL( toggled( bool ) ), SLOT( onAnglesCheck() ) ); + connect( BasePointCheck, SIGNAL( toggled( bool ) ), SLOT( onBasePointCheck() ) ); + + AnglesList->installEventFilter( this ); + ElementsLineEdit->installEventFilter( this ); + StartPointLineEdit->installEventFilter( this ); + XSpin->editor()->installEventFilter( this ); + YSpin->editor()->installEventFilter( this ); + ZSpin->editor()->installEventFilter( this ); + + /***************************************************************/ + // set position and show dialog box + int x, y ; + mySMESHGUI->DefineDlgPosition( this, x, y ) ; + this->move( x, y ) ; + this->show() ; // displays Dialog +} + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::~SMESHGUI_ExtrusionAlongPathDlg() +// purpose : destructor +//================================================================================= +SMESHGUI_ExtrusionAlongPathDlg::~SMESHGUI_ExtrusionAlongPathDlg() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::~SMESHGUI_ExtrusionAlongPathDlg"); + // no need to delete child widgets, Qt does it all for us +} + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::eventFilter +// purpose : event filter +//================================================================================= +bool SMESHGUI_ExtrusionAlongPathDlg::eventFilter( QObject* object, QEvent* event ) +{ + if ( event->type() == QEvent::KeyPress ) { + QKeyEvent* ke = ( QKeyEvent* )event; + if ( object == AnglesList ) { + if ( ke->key() == Key_Delete ) + OnAngleRemoved(); + } + } + else if ( event->type() == QEvent::FocusIn ) { + if ( object == ElementsLineEdit ) { + if ( myEditCurrentArgument != ElementsLineEdit ) + SetEditCurrentArgument( SelectElementsButton ); + } + else if ( object == StartPointLineEdit ) { + if ( myEditCurrentArgument != StartPointLineEdit ) + SetEditCurrentArgument( SelectStartPointButton ); + } + else if ( object == XSpin->editor() || object == YSpin->editor() || object == ZSpin->editor() ) { + if ( myEditCurrentArgument != XSpin ) + SetEditCurrentArgument( SelectBasePointButton ); + } + } + return QDialog::eventFilter( object, event ); +} + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::Init() +// purpose : initialization +//================================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::Init( bool ResetControls ) +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::Init"); + myBusy = false; + myEditCurrentArgument = 0; + + myMesh = SMESH::SMESH_Mesh::_nil(); + myIDSource = SMESH::SMESH_IDSource::_nil(); + myMeshActor = 0; + myPathMesh = SMESH::SMESH_Mesh::_nil(); + myPathShape = GEOM::GEOM_Object::_nil(); + + ElementsLineEdit->clear(); + PathMeshLineEdit->clear(); + PathShapeLineEdit->clear(); + StartPointLineEdit->clear(); + + if( ResetControls ) { + XSpin->SetValue( 0.0 ); + YSpin->SetValue( 0.0 ); + ZSpin->SetValue( 0.0 ); + + AngleSpin->SetValue( 45 ); + MeshCheck->setChecked( false ); + TypeChanged( 0 ); + onSelectMesh(); + onAnglesCheck(); + onBasePointCheck(); + } + SetEditCurrentArgument( 0 ); +} + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::TypeChanged() +// purpose : Called when user changes type of elements ( 1d / 2d ) +//================================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::TypeChanged( int type ) +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::TypeChanged"); + if ( myType != type ) { + disconnect( mySelection, 0, this, 0 ); + + if ( type == 0 ) + ArgumentsGrp->setTitle( tr( "EXTRUSION_1D" ) ); + else if ( type == 1 ) + ArgumentsGrp->setTitle( tr( "EXTRUSION_2D" ) ); + + // clear elements ID list + if ( !MeshCheck->isChecked() ) { + ElementsLineEdit->clear(); + } + // set selection mode if necessary + if( myEditCurrentArgument == ElementsLineEdit ) { + mySelection->ClearIObjects(); + mySelection->ClearFilters(); + SMESH::SetPickable(); + + SMESH::SetPointRepresentation( false ); + if ( MeshCheck->isChecked() ) { + QAD_Application::getDesktop()->SetSelectionMode( ActorSelection ); + mySelection->AddFilter( myElementsFilter ); + } + else { + if ( type == 0 ) + QAD_Application::getDesktop()->SetSelectionMode( EdgeSelection, true ); + if ( type == 1 ) + QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true ); + } + } + connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + } + myType = type; +} + + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply() +// purpose : Called when user presses button +//================================================================================= +bool SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply"); + if ( mySMESHGUI->ActiveStudyLocked() ) { + return false; + } + + if( myMesh->_is_nil() || MeshCheck->isChecked() && myIDSource->_is_nil() || !myMeshActor || myPathMesh->_is_nil() || myPathShape->_is_nil() ) { + return false; + } + + SMESH::long_array_var anElementsId = new SMESH::long_array; + + if ( MeshCheck->isChecked() ) { + // If "Select whole mesh, submesh or group" check box is on -> + // get all elements of the required type from the object selected + + // if MESH object is selected + if ( !CORBA::is_nil( SMESH::SMESH_Mesh::_narrow( myIDSource ) ) ) { + // get mesh + SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( myIDSource ); + // get IDs from mesh... + if ( Elements1dRB->isChecked() ) + // 1d elements + anElementsId = aMesh->GetElementsByType( SMESH::EDGE ); + else if ( Elements2dRB->isChecked() ) { + anElementsId = aMesh->GetElementsByType( SMESH::FACE ); + } + } + // SUBMESH is selected + if ( !CORBA::is_nil( SMESH::SMESH_subMesh::_narrow( myIDSource ) ) ) { + // get submesh + SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( myIDSource ); + // get IDs from submesh + if ( Elements1dRB->isChecked() ) + // 1d elements + anElementsId = aSubMesh->GetElementsByType( SMESH::EDGE ); + else if ( Elements2dRB->isChecked() ) + // 2d elements + anElementsId = aSubMesh->GetElementsByType( SMESH::FACE ); + } + // GROUP is selected + if ( !CORBA::is_nil( SMESH::SMESH_GroupBase::_narrow( myIDSource ) ) ) { + // get smesh group + SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( myIDSource ); + // get IDs from group + // 1d elements or 2d elements + if ( Elements1dRB->isChecked() && aGroup->GetType() == SMESH::EDGE || + Elements2dRB->isChecked() && aGroup->GetType() == SMESH::FACE ) + anElementsId = aGroup->GetListOfID(); + } + } + else { + // If "Select whole mesh, submesh or group" check box is off -> + // use only elements of given type selected by user + + SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh(); + if ( aMesh ) { + QStringList aListElementsId = QStringList::split( " ", ElementsLineEdit->text(), false ); + anElementsId = new SMESH::long_array; + anElementsId->length( aListElementsId.count() ); + bool bOk; + int j = 0; + for ( int i = 0; i < aListElementsId.count(); i++ ) { + long ind = aListElementsId[ i ].toLong( &bOk ); + if ( bOk ) { + const SMDS_MeshElement* e = aMesh->FindElement( ind ); + if ( e ) { + bool typeMatch = Elements1dRB->isChecked() && e->GetType() == SMDSAbs_Edge || + Elements2dRB->isChecked() && e->GetType() == SMDSAbs_Face; + if ( typeMatch ) + anElementsId[ j++ ] = ind; + } + } + } + anElementsId->length( j ); + } + } + + if ( anElementsId->length() <= 0 ) { + return false; + } + + if ( StartPointLineEdit->text().stripWhiteSpace().isEmpty() ) { + return false; + } + + bool bOk; + long aNodeStart = StartPointLineEdit->text().toLong( &bOk ); + if ( !bOk ) { + return false; + } + + // get angles + SMESH::double_array_var anAngles = new SMESH::double_array; + if ( AnglesCheck->isChecked() ) { + anAngles->length( AnglesList->count() ); + int j = 0; + bool bOk; + for ( int i = 0; i < AnglesList->count(); i++ ) { + long angle = AnglesList->text( i ).toLong( &bOk ); + if ( bOk ) + anAngles[ j++ ] = angle; + } + anAngles->length( j ); + } + + // get base point + SMESH::PointStruct aBasePoint; + if ( BasePointCheck->isChecked() ) { + aBasePoint.x = XSpin->GetValue(); + aBasePoint.y = YSpin->GetValue(); + aBasePoint.z = ZSpin->GetValue(); + } + + try { + QAD_WaitCursor wc; + SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); + aMeshEditor->ExtrusionAlongPath( anElementsId.inout(), myPathMesh, myPathShape, aNodeStart, + AnglesCheck->isChecked(), anAngles.inout(), + BasePointCheck->isChecked(), aBasePoint ); + } + catch( ... ) { + return false; + } + + mySelection->ClearIObjects(); + SMESH::UpdateView(); + Init( false ); + TypeChanged( GetConstructorId() ); + return true; +} + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::ClickOnOk() +// purpose : Called when user presses button +//================================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::ClickOnOk() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::ClickOnOk"); + if ( !ClickOnApply() ) + return; + reject(); +} + +//======================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::onTextChange +// purpose : +//======================================================================= + +void SMESHGUI_ExtrusionAlongPathDlg::onTextChange(const QString& theNewText) +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::onTextChange"); + QLineEdit* send = (QLineEdit*)sender(); + if ( send != StartPointLineEdit && send != ElementsLineEdit ) + send = ElementsLineEdit; + + // return if busy + if ( myBusy ) + return; + + // set busy flag + SetBusy sb( this ); + + if ( send == ElementsLineEdit && myEditCurrentArgument == ElementsLineEdit ) { + // hilight entered elements + SMDS_Mesh* aMesh = 0; + if ( myMeshActor ) + aMesh = myMeshActor->GetObject()->GetMesh(); + if ( aMesh ) { + mySelection->ClearIObjects(); + mySelection->AddIObject( myMeshActor->getIO() ); + + QStringList aListId = QStringList::split( " ", theNewText, false ); + bool bOk; + for ( int i = 0; i < aListId.count(); i++ ) { + long ind = aListId[ i ].toLong( &bOk ); + if ( bOk ) { + const SMDS_MeshElement* e = aMesh->FindElement( ind ); + if ( e ) { + // check also type of element + bool typeMatch = Elements1dRB->isChecked() && e->GetType() == SMDSAbs_Edge || + Elements2dRB->isChecked() && e->GetType() == SMDSAbs_Face; + if ( typeMatch ) { + if ( !mySelection->IsIndexSelected( myMeshActor->getIO(), e->GetID() ) ) + mySelection->AddOrRemoveIndex( myMeshActor->getIO(), e->GetID(), true ); + } + } + } + } + } + } + else if ( send == StartPointLineEdit && myEditCurrentArgument == StartPointLineEdit ) { + if ( !myPathMesh->_is_nil() ) { + SMESH_Actor* aPathActor = SMESH::FindActorByObject( myPathMesh ); + SMDS_Mesh* aMesh = 0; + if ( aPathActor ) + aMesh = aPathActor->GetObject()->GetMesh(); + if ( aMesh ) { + mySelection->ClearIObjects(); + mySelection->AddIObject( aPathActor->getIO() ); + + bool bOk; + long ind = theNewText.toLong( &bOk ); + if ( bOk ) { + const SMDS_MeshNode* n = aMesh->FindNode( ind ); + if ( n ) { + if ( !mySelection->IsIndexSelected( aPathActor->getIO(), n->GetID() ) ) { + mySelection->AddOrRemoveIndex( aPathActor->getIO(), n->GetID(), true ); + } + } + } + } + } + } +} + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::SelectionIntoArgument() +// purpose : Called when selection as changed or other case +//================================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::SelectionIntoArgument() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::SelectionIntoArgument"); + // return if busy + if ( myBusy ) + return; + + // return if dialog box is inactive + if ( !ButtonsGrp->isEnabled() ) + return; + + // selected objects count + int nbSel = mySelection->IObjectCount(); + + // set busy flag + SetBusy sb( this ); + + if ( myEditCurrentArgument == ElementsLineEdit ) { + // we are now selecting mesh elements (or whole mesh/submesh/group) + // reset + ElementsLineEdit->clear(); + myMesh = SMESH::SMESH_Mesh::_nil(); + myIDSource = SMESH::SMESH_IDSource::_nil(); + myMeshActor = 0; + + // only one object is acceptable + if( nbSel != 1 ) + return; + + // try to get mesh from selection + Handle( SALOME_InteractiveObject ) IO = mySelection->firstIObject(); + myMesh = SMESH::GetMeshByIO( IO ); + if( myMesh->_is_nil() ) + return; + // find actor + myMeshActor = SMESH::FindActorByObject( myMesh ); + if ( !myMeshActor ) + return; + + if ( MeshCheck->isChecked() ) { + // If "Select whole mesh, submesh or group" check box is on -> + // get ID source and put it's name to the edit box + QString aString; + SMESH::GetNameOfSelectedIObjects( mySelection, aString ); + + myIDSource = SMESH::IObjectToInterface( IO ); + ElementsLineEdit->setText( aString ); + } + else { + // If "Select whole mesh, submesh or group" check box is off -> + // try to get selected elements IDs + QString aString; + int aNbUnits = SMESH::GetNameOfSelectedElements( mySelection, aString ); + ElementsLineEdit->setText( aString ); + } + } + else if ( myEditCurrentArgument == PathMeshLineEdit ) { + // we are now selecting path mesh + // reset + PathMeshLineEdit->clear(); + myPathMesh = SMESH::SMESH_Mesh::_nil(); + PathShapeLineEdit->clear(); + myPathShape = GEOM::GEOM_Object::_nil(); + StartPointLineEdit->clear(); + + // only one object is acceptable + if( nbSel != 1 ) + return; + + // try to get mesh from selection + Handle( SALOME_InteractiveObject ) IO = mySelection->firstIObject(); + myPathMesh = SMESH::IObjectToInterface( IO ); + if( myPathMesh->_is_nil() ) + return; + + QString aString; + SMESH::GetNameOfSelectedIObjects( mySelection, aString ); + PathMeshLineEdit->setText( aString ); + } + else if ( myEditCurrentArgument == PathShapeLineEdit ) { + // we are now selecting path mesh + // reset + PathShapeLineEdit->clear(); + myPathShape = GEOM::GEOM_Object::_nil(); + StartPointLineEdit->clear(); + + // return if path mesh is not yet selected + if ( myPathMesh->_is_nil() ) + return; + + // only one object is acceptable + if( nbSel != 1 ) + return; + + // try to get shape from selection + Handle( SALOME_InteractiveObject ) IO = mySelection->firstIObject(); + myPathShape = SMESH::IObjectToInterface( IO ); + if ( myPathShape->_is_nil() ) + return; + + QString aString; + SMESH::GetNameOfSelectedIObjects( mySelection, aString ); + PathShapeLineEdit->setText( aString ); + } + else if ( myEditCurrentArgument == StartPointLineEdit ) { + // we are now selecting start point of path + // reset + StartPointLineEdit->clear(); + + // return if path mesh or path shape is not yet selected + if ( myPathMesh->_is_nil() || myPathShape->_is_nil() ) + return; + + // only one object is acceptable + if( nbSel != 1 ) + return; + + // try to get shape from selection + Handle( SALOME_InteractiveObject ) IO = mySelection->firstIObject(); + + QString aString; + int aNbUnits = SMESH::GetNameOfSelectedElements( mySelection, aString ); + if ( aNbUnits == 1 ) + StartPointLineEdit->setText( aString.stripWhiteSpace() ); + } + else if ( myEditCurrentArgument == XSpin ) { + // we are now selecting base point + // reset is not performed here! + + // return if is not enabled + if ( !BasePointGrp->isEnabled() ) + return; + + // only one object is acceptable + if( nbSel != 1 ) + return; + + // try to get shape from selection + Handle( SALOME_InteractiveObject ) IO = mySelection->firstIObject(); + + // check if geom vertex is selected + GEOM::GEOM_Object_var aGeomObj = SMESH::IObjectToInterface( IO ); + TopoDS_Vertex aVertex; + if( !aGeomObj->_is_nil() ) { + if( aGeomObj->IsShape() && GEOMBase::GetShape( aGeomObj, aVertex ) && !aVertex.IsNull() ) { + gp_Pnt aPnt = BRep_Tool::Pnt( aVertex ); + XSpin->SetValue( aPnt.X() ); + YSpin->SetValue( aPnt.Y() ); + ZSpin->SetValue( aPnt.Z() ); + } + return; + } + + // check if smesh node is selected + SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO ); + if( aMesh->_is_nil() ) + return; + + QString aString; + int aNbUnits = SMESH::GetNameOfSelectedNodes( mySelection, aString ); + // return if more than one node is selected + if( aNbUnits != 1 ) + return; + + SMESH_Actor* aMeshActor = SMESH::FindActorByObject( aMesh ); + if ( !aMeshActor ) + return; + + SMDS_Mesh* mesh = aMeshActor->GetObject()->GetMesh(); + if (!mesh) + return; + + const SMDS_MeshNode* n = mesh->FindNode( aString.toLong() ); + if ( !n ) + return; + + XSpin->SetValue( n->X() ); + YSpin->SetValue( n->Y() ); + ZSpin->SetValue( n->Z() ); + } +} + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument() +// purpose : +//================================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument"); + QToolButton* send = (QToolButton*)sender(); + if ( send != SelectElementsButton && + send != SelectPathMeshButton && + send != SelectPathShapeButton && + send != SelectStartPointButton && + send != SelectBasePointButton ) + return; + SetEditCurrentArgument( send ); +} + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument() +// purpose : +//================================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument( QToolButton* button ) +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument(button)"); + disconnect( mySelection, 0, this, 0 ); + mySelection->ClearIObjects(); + mySelection->ClearFilters(); + SMESH::SetPickable(); + + if( button == SelectElementsButton ) { + myEditCurrentArgument = ElementsLineEdit; + SMESH::SetPointRepresentation( false ); + if ( MeshCheck->isChecked() ) { + QAD_Application::getDesktop()->SetSelectionMode( ActorSelection ); + mySelection->AddFilter( myElementsFilter ); + } + else { + if ( Elements1dRB->isChecked() ) + QAD_Application::getDesktop()->SetSelectionMode( EdgeSelection, true ); + else if ( Elements2dRB->isChecked() ) + QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true ); + } + } + else if ( button == SelectPathMeshButton ) { + myEditCurrentArgument = PathMeshLineEdit; + SMESH::SetPointRepresentation( false ); + QAD_Application::getDesktop()->SetSelectionMode( ActorSelection ); + mySelection->AddFilter( myPathMeshFilter ); + } + else if ( button == SelectPathShapeButton ) { + myEditCurrentArgument = PathShapeLineEdit; + SMESH::SetPointRepresentation( false ); + QAD_Application::getDesktop()->SetSelectionMode( ActorSelection ); + + if ( !myPathMesh->_is_nil() ) { + TColStd_MapOfInteger aTypes; + aTypes.Add( TopAbs_EDGE ); + aTypes.Add( TopAbs_WIRE ); + GEOM::GEOM_Object_var aMainShape = myPathMesh->GetShapeToMesh(); + SMESH_Actor* aPathActor = SMESH::FindActorByObject( myPathMesh ); + + if ( !aMainShape->_is_nil() && aPathActor ) + mySelection->AddFilter( new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, -1, aTypes, aMainShape ) ); + //SMESH::SetPickable( aPathActor ); + } + } + else if ( button == SelectStartPointButton ) { + myEditCurrentArgument = StartPointLineEdit; + if ( !myPathMesh->_is_nil() ) { + SMESH_Actor* aPathActor = SMESH::FindActorByObject( myPathMesh ); + if ( aPathActor ) { + SMESH::SetPointRepresentation( true ); + QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true ); + SMESH::SetPickable( aPathActor ); + } + } + } + else if ( button == SelectBasePointButton ) { + myEditCurrentArgument = XSpin; + SMESH::SetPointRepresentation( true ); + QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true ); + + SMESH_ListOfFilter aListOfFilters; + Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH ); + if ( !aMeshOrSubMeshFilter.IsNull() ) + aListOfFilters.Append( aMeshOrSubMeshFilter ); + Handle(SMESH_TypeFilter) aSmeshGroupFilter = new SMESH_TypeFilter( GROUP ); + if ( !aSmeshGroupFilter.IsNull() ) + aListOfFilters.Append( aSmeshGroupFilter ); + //Handle(GEOM_ShapeTypeFilter) aVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX ); + Handle(SMESH_NumberFilter) aVertexFilter = new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, -1, TopAbs_VERTEX, GEOM::GEOM_Object::_nil() ); + if ( !aVertexFilter.IsNull() ) + aListOfFilters.Append( aVertexFilter ); + + mySelection->AddFilter( new SMESH_LogicalFilter( aListOfFilters, SMESH_LogicalFilter::LO_OR ) ); + } + + if ( myEditCurrentArgument && !myEditCurrentArgument->hasFocus() ) + myEditCurrentArgument->setFocus(); + + connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + SelectionIntoArgument(); +} + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::DeactivateActiveDialog() +// purpose : Deactivates this dialog +//================================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::DeactivateActiveDialog() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::DeactivateActiveDialog"); + if ( ElementsTypeGrp->isEnabled() ) { + ElementsTypeGrp->setEnabled( false ); + ArgumentsGrp->setEnabled( false ); + ButtonsGrp->setEnabled( false ); + mySMESHGUI->ResetState(); + mySMESHGUI->SetActiveDialogBox( 0 ); + } +} + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::ActivateThisDialog() +// purpose : Activates this dialog +//================================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::ActivateThisDialog() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::ActivateThisDialog"); + // Emit a signal to deactivate the active dialog + mySMESHGUI->EmitSignalDeactivateDialog(); + ElementsTypeGrp->setEnabled( true ); + ArgumentsGrp->setEnabled( true ); + ButtonsGrp->setEnabled( true ); + + mySMESHGUI->SetActiveDialogBox( this ); + + TypeChanged( GetConstructorId() ); + SelectionIntoArgument(); +} + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::enterEvent() +// purpose : Mouse enter event +//================================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::enterEvent(QEvent* e) +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::enterEvent"); + if ( ElementsTypeGrp->isEnabled() ) + return; + ActivateThisDialog(); +} + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::reject() +// purpose : Called when dialog box is closed +//================================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::reject() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::reject"); + disconnect( mySelection, 0, this, 0 ); + mySelection->ClearFilters(); + mySelection->ClearIObjects(); + SMESH::SetPickable(); + SMESH::SetPointRepresentation( false ); + QAD_Application::getDesktop()->SetSelectionMode( ActorSelection ); + mySMESHGUI->ResetState() ; + QDialog::reject(); +} + +//================================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::GetConstructorId() +// purpose : +//================================================================================= +int SMESHGUI_ExtrusionAlongPathDlg::GetConstructorId() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::GetConstructorId"); + if ( ElementsTypeGrp != NULL && ElementsTypeGrp->selected() != NULL ) + return ElementsTypeGrp->id( ElementsTypeGrp->selected() ); + return -1; +} + +//======================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::onSelectMesh +// purpose : +//======================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::onSelectMesh() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::onSelectMesh"); + bool toSelectMesh = MeshCheck->isChecked(); + + ElementsLineEdit->setReadOnly( toSelectMesh ); + ElementsLab->setText( toSelectMesh ? tr( "SMESH_NAME" ) : tr( "SMESH_ID_ELEMENTS" ) ); + ElementsLineEdit->clear(); + + SetEditCurrentArgument( SelectElementsButton ); +} + +//======================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::onAnglesCheck +// purpose : called when "Use Angles" check box is switched +//======================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::onAnglesCheck() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::onAnglesCheck"); + AnglesGrp->setEnabled( AnglesCheck->isChecked() ); +} + +//======================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::onBasePointCheck +// purpose : called when "Use Base Point" check box is switched +//======================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::onBasePointCheck() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::onBasePointCheck"); + BasePointGrp->setEnabled( BasePointCheck->isChecked() ); +} + +//======================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::OnAngleAdded +// purpose : Called when user adds angle to the list +//======================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::OnAngleAdded() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::OnAngleAdded"); + AnglesList->insertItem( QString::number( AngleSpin->GetValue() ) ); +} + +//======================================================================= +// function : SMESHGUI_ExtrusionAlongPathDlg::OnAngleRemoved +// purpose : Called when user removes angle(s) from the list +//======================================================================= +void SMESHGUI_ExtrusionAlongPathDlg::OnAngleRemoved() +{ + MESSAGE("SMESHGUI_ExtrusionAlongPathDlg::OnAngleRemoved"); + QList aList; + aList.setAutoDelete( false ); + for ( int i = 0; i < AnglesList->count(); i++ ) + if ( AnglesList->isSelected( i ) ) + aList.append( AnglesList->item( i ) ); + + for ( int i = 0; i < aList.count(); i++ ) + delete aList.at( i ); +} + diff --git a/src/SMESHGUI/SMESHGUI_ExtrusionAlongPathDlg.h b/src/SMESHGUI/SMESHGUI_ExtrusionAlongPathDlg.h new file mode 100644 index 000000000..951dbb3ef --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_ExtrusionAlongPathDlg.h @@ -0,0 +1,156 @@ +// SMESH SMESHGUI : GUI for SMESH component +// +// 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 : SMESHGUI_ExtrusionAlongPathDlg.h +// Author : Vadim SANDLER +// Module : SMESH +// $Header: + +#ifndef DIALOGBOX_EXTRUSION_PATH_H +#define DIALOGBOX_EXTRUSION_PATH_H + +#include "SALOME_Selection.h" +#include "SMESH_LogicalFilter.hxx" +#include "SMESH_TypeFilter.hxx" +// QT Includes +#include + +class QButtonGroup; +class QRadioButton; +class QGroupBox; +class QLabel; +class QToolButton; +class QLineEdit; +class QCheckBox; +class QListBox; +class QPushButton; +class SMESHGUI_SpinBox; +class SMESHGUI; +class SMESH_Actor; + +// IDL Headers +#include +#include CORBA_SERVER_HEADER(SMESH_Mesh) + +//================================================================================= +// class : SMESHGUI_ExtrusionAlongPathDlg +// purpose : +//================================================================================= +class SMESHGUI_ExtrusionAlongPathDlg : public QDialog +{ + Q_OBJECT + + class SetBusy { + public: + SetBusy( SMESHGUI_ExtrusionAlongPathDlg* _dlg ) { myDlg = _dlg; myDlg->myBusy = true; } + ~SetBusy() { myDlg->myBusy = false; } + private: + SMESHGUI_ExtrusionAlongPathDlg* myDlg; + }; + friend class SetBusy; + +public: + SMESHGUI_ExtrusionAlongPathDlg( QWidget* parent = 0, SALOME_Selection* Sel = 0, bool modal = FALSE ); + ~SMESHGUI_ExtrusionAlongPathDlg(); + + bool eventFilter( QObject* object, QEvent* event ); + +protected slots: + void reject(); + +private: + void Init( bool ResetControls = true ) ; + void enterEvent ( QEvent * ) ; /* mouse enter the QWidget */ + int GetConstructorId(); + void SetEditCurrentArgument( QToolButton* button ); + + SMESHGUI* mySMESHGUI ; /* Current SMESHGUI object */ + SALOME_Selection* mySelection ; /* User shape selection */ + QWidget* myEditCurrentArgument; /* Current argument */ + + bool myBusy; + SMESH::SMESH_IDSource_var myIDSource; + SMESH::SMESH_Mesh_var myMesh; + SMESH_Actor* myMeshActor; + SMESH::SMESH_Mesh_var myPathMesh; + GEOM::GEOM_Object_var myPathShape; + Handle(SMESH_LogicalFilter) myElementsFilter; + Handle(SMESH_TypeFilter) myPathMeshFilter; + int myType; + + // widgets + QButtonGroup* ElementsTypeGrp; + QRadioButton* Elements1dRB; + QRadioButton* Elements2dRB; + QGroupBox* ArgumentsGrp; + QLabel* ElementsLab; + QToolButton* SelectElementsButton; + QLineEdit* ElementsLineEdit; + QCheckBox* MeshCheck; + QGroupBox* PathGrp; + QLabel* PathMeshLab; + QToolButton* SelectPathMeshButton; + QLineEdit* PathMeshLineEdit; + QLabel* PathShapeLab; + QToolButton* SelectPathShapeButton; + QLineEdit* PathShapeLineEdit; + QLabel* StartPointLab; + QToolButton* SelectStartPointButton; + QLineEdit* StartPointLineEdit; + QCheckBox* AnglesCheck; + QGroupBox* AnglesGrp; + QListBox* AnglesList; + QToolButton* AddAngleButton; + QToolButton* RemoveAngleButton; + SMESHGUI_SpinBox* AngleSpin; + QCheckBox* BasePointCheck; + QGroupBox* BasePointGrp; + QToolButton* SelectBasePointButton; + QLabel* XLab; + SMESHGUI_SpinBox* XSpin; + QLabel* YLab; + SMESHGUI_SpinBox* YSpin; + QLabel* ZLab; + SMESHGUI_SpinBox* ZSpin; + QGroupBox* ButtonsGrp; + QPushButton* OkButton; + QPushButton* ApplyButton; + QPushButton* CloseButton; + +private slots: + void TypeChanged( int type ); + void ClickOnOk(); + bool ClickOnApply(); + void SetEditCurrentArgument(); + void SelectionIntoArgument(); + void DeactivateActiveDialog(); + void ActivateThisDialog(); + void onTextChange(const QString&); + void onSelectMesh(); + void onAnglesCheck(); + void onBasePointCheck(); + void OnAngleAdded(); + void OnAngleRemoved(); +}; + +#endif // DIALOGBOX_EXTRUSION_PATH_H diff --git a/src/SMESHGUI/SMESHGUI_ExtrusionDlg.cxx b/src/SMESHGUI/SMESHGUI_ExtrusionDlg.cxx index c47fa7a5b..7e3ad503f 100644 --- a/src/SMESHGUI/SMESHGUI_ExtrusionDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_ExtrusionDlg.cxx @@ -56,6 +56,10 @@ #include #include +// IDL Headers +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SMESH_Group) + using namespace std; //================================================================================= diff --git a/src/SMESHGUI/SMESHGUI_FilterDlg.cxx b/src/SMESHGUI/SMESHGUI_FilterDlg.cxx index 7aeb763d3..f20b321ca 100755 --- a/src/SMESHGUI/SMESHGUI_FilterDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_FilterDlg.cxx @@ -81,6 +81,10 @@ #include #include +// IDL Headers +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SMESH_Group) + #define SPACING 5 #define MARGIN 10 @@ -654,7 +658,8 @@ bool SMESHGUI_FilterTable::IsValid( const bool theMess, const int theEntityType if ( aCriterion == FT_RangeOfIds || aCriterion == FT_BelongToGeom || aCriterion == FT_BelongToPlane || - aCriterion == FT_BelongToCylinder ) + aCriterion == FT_BelongToCylinder || + aCriterion == FT_LyingOnGeom) { if ( aTable->text( i, 2 ).isEmpty() ) { @@ -768,7 +773,8 @@ void SMESHGUI_FilterTable::GetCriterion( const int theRow, if ( aCriterionType != FT_RangeOfIds && aCriterionType != FT_BelongToGeom && aCriterionType != FT_BelongToPlane && - aCriterionType != FT_BelongToCylinder ) + aCriterionType != FT_BelongToCylinder && + aCriterionType != FT_LyingOnGeom) { theCriterion.Compare = ( (ComboItem*)aTable->item( theRow, 1 ) )->GetValue(); theCriterion.Threshold = aTable->item( theRow, 2 )->text().toDouble(); @@ -813,7 +819,8 @@ void SMESHGUI_FilterTable::SetCriterion( const int theRow, if ( theCriterion.Type != FT_RangeOfIds && theCriterion.Type != FT_BelongToGeom && theCriterion.Type != FT_BelongToPlane && - theCriterion.Type != FT_BelongToCylinder ) + theCriterion.Type != FT_BelongToCylinder && + theCriterion.Type != FT_LyingOnGeom) aTable->setText( theRow, 2, QString( "%1" ).arg( theCriterion.Threshold, 0, 'g', 15 ) ); else aTable->setText( theRow, 2, QString( theCriterion.ThresholdStr ) ); @@ -902,7 +909,6 @@ void SMESHGUI_FilterTable::onAddBtn() int aType = GetType(); addRow( myTables[ aType ], aType ); - Table* aTable = myTables[ aType ]; Update(); } @@ -965,6 +971,7 @@ void SMESHGUI_FilterTable::updateAdditionalWidget() ComboItem* anItem = ( (ComboItem*)aTable->item( aRow, 0 ) ); bool toEnable = ( (ComboItem*)aTable->item( aRow, 1 ) )->GetValue() == FT_EqualTo && GetCriterionType( aRow ) != FT_BelongToGeom && + GetCriterionType( aRow ) != FT_LyingOnGeom && GetCriterionType( aRow ) != FT_RangeOfIds && GetCriterionType( aRow ) != FT_FreeEdges; if ( !myAddWidgets.contains( anItem ) ) @@ -1047,7 +1054,8 @@ void SMESHGUI_FilterTable::onCriterionChanged( const int row, const int col, con else if ( aCriterionType == SMESH::FT_RangeOfIds || aCriterionType == SMESH::FT_BelongToGeom || aCriterionType == SMESH::FT_BelongToPlane || - aCriterionType == SMESH::FT_BelongToCylinder ) + aCriterionType == SMESH::FT_BelongToCylinder || + aCriterionType == SMESH::FT_LyingOnGeom) { QMap aMap; aMap[ FT_EqualTo ] = tr( "EQUAL_TO" ); @@ -1239,6 +1247,7 @@ const QMap& SMESHGUI_FilterTable::getCriteria( const int theType ) aCriteria[ SMESH::FT_BelongToGeom ] = tr( "BELONG_TO_GEOM" ); aCriteria[ SMESH::FT_BelongToPlane ] = tr( "BELONG_TO_PLANE" ); aCriteria[ SMESH::FT_BelongToCylinder ] = tr( "BELONG_TO_CYLINDER" ); + aCriteria[ SMESH::FT_LyingOnGeom ] = tr( "LYING_ON_GEOM" ); } return aCriteria; } @@ -1254,6 +1263,7 @@ const QMap& SMESHGUI_FilterTable::getCriteria( const int theType ) aCriteria[ SMESH::FT_BelongToGeom ] = tr( "BELONG_TO_GEOM" ); aCriteria[ SMESH::FT_BelongToPlane ] = tr( "BELONG_TO_PLANE" ); aCriteria[ SMESH::FT_BelongToCylinder ] = tr( "BELONG_TO_CYLINDER" ); + aCriteria[ SMESH::FT_LyingOnGeom ] = tr( "LYING_ON_GEOM" ); } return aCriteria; } @@ -1273,6 +1283,9 @@ const QMap& SMESHGUI_FilterTable::getCriteria( const int theType ) aCriteria[ SMESH::FT_BelongToGeom ] = tr( "BELONG_TO_GEOM" ); aCriteria[ SMESH::FT_BelongToPlane ] = tr( "BELONG_TO_PLANE" ); aCriteria[ SMESH::FT_BelongToCylinder ] = tr( "BELONG_TO_CYLINDER" ); + aCriteria[ SMESH::FT_LyingOnGeom ] = tr( "LYING_ON_GEOM" ); + aCriteria[ SMESH::FT_Length2D ] = tr( "LENGTH2D" ); + aCriteria[ SMESH::FT_MultiConnection2D] = tr( "MULTI2D_BORDERS" ); } return aCriteria; } @@ -1281,8 +1294,10 @@ const QMap& SMESHGUI_FilterTable::getCriteria( const int theType ) static QMap aCriteria; if ( aCriteria.isEmpty() ) { + aCriteria[ SMESH::FT_AspectRatio3D] = tr( "ASPECT_RATIO_3D" ); aCriteria[ SMESH::FT_RangeOfIds ] = tr( "RANGE_OF_IDS" ); aCriteria[ SMESH::FT_BelongToGeom ] = tr( "BELONG_TO_GEOM" ); + aCriteria[ SMESH::FT_LyingOnGeom ] = tr( "LYING_ON_GEOM" ); } return aCriteria; } @@ -1341,9 +1356,6 @@ SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable( QWidget* thePar static int aLenCr = abs( aMaxLenCr - aMetrics.width( tr( "CRITERION" ) ) ) / aMetrics.width( ' ' ) + 5; - static int aLenCo = abs( maxLength( getCompare(), aMetrics ) - - aMetrics.width( tr( "COMPARE" ) ) ) / aMetrics.width( ' ' ) + 5; - QString aCrStr; aCrStr.fill( ' ', aLenCr ); QString aCoStr; @@ -1999,7 +2011,8 @@ bool SMESHGUI_FilterDlg::isValid() const int aType = myTable->GetCriterionType( i ); if ( aType == FT_BelongToGeom || aType == FT_BelongToPlane || - aType == FT_BelongToCylinder ) + aType == FT_BelongToCylinder || + aType == FT_LyingOnGeom) { QString aName; myTable->GetThreshold( i, aName ); @@ -2312,7 +2325,7 @@ void SMESHGUI_FilterDlg::filterSelectionSource( const int theType, if ( aSelMap.Extent() > 0 ) { - if(SMESH_Actor *anActor = SMESH::FindActorByEntry( anIter.Key()->getEntry() ) ) + if( SMESH::FindActorByEntry( anIter.Key()->getEntry() ) ) { for ( int i = 1; i <= aSelMap.Extent(); i++ ) aToBeFiltered.Add( aSelMap(i) ); @@ -2418,7 +2431,8 @@ void SMESHGUI_FilterDlg::onSelectionDone() !myTable->CurrentCell( aRow, aCol ) || myTable->GetCriterionType( aRow ) != FT_BelongToGeom && myTable->GetCriterionType( aRow ) != FT_BelongToPlane && - myTable->GetCriterionType( aRow ) != FT_BelongToCylinder) + myTable->GetCriterionType( aRow ) != FT_BelongToCylinder && + myTable->GetCriterionType( aRow ) != FT_LyingOnGeom ) return; Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject() ; @@ -2461,9 +2475,10 @@ void SMESHGUI_FilterDlg::updateSelection() if ( myTable->CurrentCell( aRow, aCol ) && ( myTable->GetCriterionType( aRow ) == FT_BelongToGeom || myTable->GetCriterionType( aRow ) == FT_BelongToPlane || - myTable->GetCriterionType( aRow ) == FT_BelongToCylinder ) ) + myTable->GetCriterionType( aRow ) == FT_BelongToCylinder || + myTable->GetCriterionType( aRow ) == FT_LyingOnGeom) ) { - if ( myTable->GetCriterionType( aRow ) == FT_BelongToGeom ) + if ( myTable->GetCriterionType( aRow ) == FT_BelongToGeom || myTable->GetCriterionType( aRow ) == FT_LyingOnGeom ) mySelection->AddFilter( new SALOME_TypeFilter( "GEOM" ) ); else if ( myTable->GetCriterionType( aRow ) == FT_BelongToPlane ) mySelection->AddFilter( new GEOM_FaceFilter( StdSelect_Plane ) ); diff --git a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx index ed7295a11..4d7445df3 100644 --- a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx @@ -498,6 +498,10 @@ void SMESHGUI_GroupDlg::onGrpTypeChanged(int id) //================================================================================= void SMESHGUI_GroupDlg::setSelectionMode(int theMode) { + // PAL7314 + if (myMesh->_is_nil()) + return; + if (mySelectionMode != theMode) { mySelection->ClearIObjects(); mySelection->ClearFilters(); diff --git a/src/SMESHGUI/SMESHGUI_MeshPatternDlg.cxx b/src/SMESHGUI/SMESHGUI_MeshPatternDlg.cxx index da8fde1c9..8e1c433b4 100755 --- a/src/SMESHGUI/SMESHGUI_MeshPatternDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshPatternDlg.cxx @@ -1,1151 +1,1372 @@ -// SMESH SMESHGUI : GUI for SMESH component -// -// 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 : SMESHGUI_MeshPatternDlg.cxx -// Author : Sergey LITONIN -// Module : SMESH - -#include "SMESHGUI_MeshPatternDlg.h" - -#include "QAD_Desktop.h" -#include "QAD_FileDlg.h" - -#include "SMESHGUI_SpinBox.h" -#include "SMESHGUI.h" -#include "SALOME_Selection.h" -#include "SMESH_NumberFilter.hxx" -#include "SMESHGUI_Utils.h" -#include "SMESHGUI_VTKUtils.h" -#include "SMESHGUI_CreatePatternDlg.h" -#include "SMESHGUI_PatternWidget.h" -#include "SMESH_Actor.h" -#include "SALOMEGUI_QtCatchCorbaException.hxx" -#include "VTKViewer_ViewFrame.h" -#include "SMESHGUI_PatternUtils.h" -#include "SMESH_ActorUtils.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#define SPACING 5 -#define MARGIN 10 - -/* - Class : SMESHGUI_MeshPatternDlg - Description : Dialog to specify filters for VTK viewer -*/ - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg -// Purpose : Constructor -//======================================================================= -SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg( QWidget* theParent, - SALOME_Selection* theSelection, - const char* theName ) -: QDialog( theParent, theName, false, - WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) -{ - setCaption( tr( "CAPTION" ) ); - - QVBoxLayout* aDlgLay = new QVBoxLayout( this, MARGIN, SPACING ); - - QFrame* aMainFrame = createMainFrame ( this ); - QFrame* aBtnFrame = createButtonFrame( this ); - - - - - aDlgLay->addWidget( aMainFrame ); - aDlgLay->addWidget( aBtnFrame ); - - aDlgLay->setStretchFactor( aMainFrame, 1 ); - - myCreationDlg = 0; - Init( theSelection ); -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::createMainFrame -// Purpose : Create frame containing dialog's input fields -//======================================================================= -QFrame* SMESHGUI_MeshPatternDlg::createMainFrame( QWidget* theParent ) -{ - QPixmap iconSlct( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) ); - QPixmap icon2d ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_2d" ) ) ); - QPixmap icon3d ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_3d" ) ) ); - QPixmap iconOpen( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_FILE_OPEN" ) ) ); - - QPixmap iconSample2d( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_2D" ) ) ); - QPixmap iconSample3d( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_3D" ) ) ); - - QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, theParent ); - aMainGrp->setFrameStyle( QFrame::NoFrame ); - aMainGrp->setInsideMargin( 0 ); - - // Pattern type group - - myTypeGrp = new QButtonGroup( 1, Qt::Vertical, tr( "PATTERN_TYPE" ), aMainGrp ); - mySwitch2d = new QRadioButton( myTypeGrp ); - mySwitch3d = new QRadioButton( myTypeGrp ); - mySwitch2d->setPixmap( icon2d ); - mySwitch3d->setPixmap( icon3d ); - myTypeGrp->insert( mySwitch2d, Type_2d ); - myTypeGrp->insert( mySwitch3d, Type_3d ); - - - // Mesh group - - QGroupBox* aMeshGrp = new QGroupBox( 1, Qt::Vertical, tr( "SMESH_MESH" ), aMainGrp ); - new QLabel( tr( "SMESH_MESH" ), aMeshGrp ); - mySelBtn[ Mesh ] = new QPushButton( aMeshGrp ); - mySelBtn[ Mesh ]->setPixmap( iconSlct ); - mySelEdit[ Mesh ] = new QLineEdit( aMeshGrp ); - mySelEdit[ Mesh ]->setReadOnly( true ); - - // Pattern group - - QGroupBox* aPatGrp = new QGroupBox( 1, Qt::Horizontal, tr( "PATTERN" ), aMainGrp ); - - // pattern name - QGroupBox* aNameGrp = new QGroupBox( 1, Qt::Vertical, aPatGrp ); - aNameGrp->setFrameStyle( QFrame::NoFrame ); - aNameGrp->setInsideMargin( 0 ); - new QLabel( tr( "PATTERN" ), aNameGrp ); - myName = new QLineEdit( aNameGrp ); - myName->setReadOnly( true ); - myOpenBtn = new QPushButton( aNameGrp ); - myOpenBtn->setPixmap( iconOpen ); - myNewBtn = new QPushButton( tr( "NEW" ), aNameGrp ); - - // selection widgets - QGroupBox* aGrp = new QGroupBox( 3, Qt::Horizontal, aPatGrp ); - aGrp->setFrameStyle( QFrame::NoFrame ); - aGrp->setInsideMargin( 0 ); - - for ( int i = Object; i <= Vertex2; i++ ) - { - mySelLbl[ i ] = new QLabel( aGrp ); - mySelBtn[ i ] = new QPushButton( aGrp ); - mySelBtn[ i ]->setPixmap( iconSlct ); - mySelEdit[ i ] = new QLineEdit( aGrp ); - mySelEdit[ i ]->setReadOnly( true ); - } - - // reverse check box - myReverseChk = new QCheckBox( tr( "REVERSE" ), aPatGrp ); - - // Pictures 2d and 3d - for ( int i = 0; i < 2; i++ ) - { - QWidget* aPreview, *aPicture; - if ( i == 0 ) - { - myPicture2d = new SMESHGUI_PatternWidget( aPatGrp ), - myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); - } - else - { - myPicture3d = new QFrame( aPatGrp ), - myPreview3d = new QLabel( myPicture3d ); - myPreview3d->setPixmap( iconSample3d ); - QGridLayout* aLay = new QGridLayout( myPicture3d, 3, 3, 0, 0 ); - QSpacerItem* aSpacerH1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ); - QSpacerItem* aSpacerH2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ); - QSpacerItem* aSpacerV1 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding ); - QSpacerItem* aSpacerV2 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding ); - aLay->addItem( aSpacerH1, 1, 0 ); - aLay->addItem( aSpacerH2, 1, 2 ); - aLay->addItem( aSpacerV1, 0, 1 ); - aLay->addItem( aSpacerV2, 2, 1 ); - aLay->addWidget( myPreview3d, 1, 1 ); - } - } - - myPreviewChk = new QCheckBox( tr( "PREVIEW" ), aPatGrp ); - - // Connect signals and slots - - connect( myTypeGrp, SIGNAL( clicked( int ) ), SLOT( onTypeChanged( int ) ) ); - connect( myOpenBtn, SIGNAL( clicked() ), SLOT( onOpen() ) ); - connect( myNewBtn, SIGNAL( clicked() ), SLOT( onNew() ) ); - connect( myReverseChk, SIGNAL( toggled( bool ) ), SLOT( onReverse( bool ) ) ); - connect( myPreviewChk, SIGNAL( toggled( bool ) ), SLOT( onPreview( bool ) ) ); - - QMap< int, QPushButton* >::iterator anIter; - for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter ) - connect( *anIter, SIGNAL( clicked() ), SLOT( onSelInputChanged() ) ); - - return aMainGrp; -} - -//======================================================================= - -// name : SMESHGUI_MeshPatternDlg::createButtonFrame -// Purpose : Create frame containing buttons -//======================================================================= -QFrame* SMESHGUI_MeshPatternDlg::createButtonFrame( QWidget* theParent ) -{ - QFrame* aFrame = new QFrame( theParent ); - aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken ); - - myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), aFrame ); - myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), aFrame ); - myCloseBtn = new QPushButton( tr( "SMESH_BUT_CLOSE" ), aFrame ); - - QSpacerItem* aSpacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ); - - QHBoxLayout* aLay = new QHBoxLayout( aFrame, MARGIN, SPACING ); - - aLay->addWidget( myOkBtn ); - aLay->addWidget( myApplyBtn ); - aLay->addItem( aSpacer); - aLay->addWidget( myCloseBtn ); - - connect( myOkBtn, SIGNAL( clicked() ), SLOT( onOk() ) ); - connect( myCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) ) ; - connect( myApplyBtn, SIGNAL( clicked() ), SLOT( onApply() ) ); - - return aFrame; -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg -// Purpose : Destructor -//======================================================================= -SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg() -{ -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::Init -// Purpose : Init dialog fields, connect signals and slots, show dialog -//======================================================================= -void SMESHGUI_MeshPatternDlg::Init( SALOME_Selection* theSelection ) -{ - myPattern = SMESH::GetPattern(); - myPreviewActor = 0; - myIsCreateDlgOpen = false; - mySelInput = Mesh; - myType = -1; - myNbPoints = -1; - mySelection = theSelection; - SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI(); - aSMESHGUI->SetActiveDialogBox( ( QDialog* )this ); - myMesh = SMESH::SMESH_Mesh::_nil(); - - myMeshShape = GEOM::GEOM_Object::_nil(); - myGeomObj[ Object ] = GEOM::GEOM_Object::_nil(); - myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil(); - myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil(); - - // selection and SMESHGUI - connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) ); - connect( aSMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( onDeactivate() ) ); - connect( aSMESHGUI, SIGNAL( SignalCloseAllDialogs() ), SLOT( onClose() ) ); - - myTypeGrp->setButton( Type_2d ); - onTypeChanged( Type_2d ); - - updateGeometry(); - - resize( minimumSize() ); - - activateSelection(); - onSelectionDone(); - - int x, y ; - aSMESHGUI->DefineDlgPosition( this, x, y ); - this->move( x, y ); - this->show(); -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::isValid -// Purpose : Verify validity of entry data -//======================================================================= -bool SMESHGUI_MeshPatternDlg::isValid( const bool theMess ) -{ - if ( myMesh->_is_nil() || myMeshShape->_is_nil() || myGeomObj[ Object ]->_is_nil() || - myGeomObj[ Vertex1 ]->_is_nil() || myType == Type_3d && myGeomObj[ Vertex2 ]->_is_nil() ) - { - if ( theMess ) - QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(), - tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SMESHGUI_INVALID_PARAMETERS" ), QMessageBox::Ok ); - return false; - } - else - return true; -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::onApply -// Purpose : SLOT called when "Apply" button pressed. -//======================================================================= -bool SMESHGUI_MeshPatternDlg::onApply() -{ - try - { - if ( !isValid() ) - return false; - - if ( myType == Type_2d ) - myPattern->ApplyToFace( - myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked() ); - else - myPattern->ApplyTo3DBlock( - myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ] ); - - if ( myPattern->MakeMesh( myMesh ) ) - { - mySelection->ClearIObjects(); - SMESH::UpdateView(); - SMESHGUI::GetSMESHGUI()->GetActiveStudy()->updateObjBrowser( true ); - return true; - } - else - { - QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(), - tr( "SMESH_ERROR" ), tr( "SMESH_OPERATION_FAILED" ), QMessageBox::Ok ); - return false; - } - } - catch( const SALOME::SALOME_Exception& S_ex ) - { - QtCatchCorbaException( S_ex ); - } - catch( ... ) - { - } - - return false; -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::onOk -// Purpose : SLOT called when "Ok" button pressed. -//======================================================================= -void SMESHGUI_MeshPatternDlg::onOk() -{ - if ( onApply() ) - onClose(); -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::onClose -// Purpose : SLOT called when "Close" button pressed. Close dialog -//======================================================================= -void SMESHGUI_MeshPatternDlg::onClose() -{ - mySelection->ClearFilters(); - QAD_Application::getDesktop()->SetSelectionMode( ActorSelection ); - disconnect( mySelection, 0, this, 0 ); - disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 ); - SMESHGUI::GetSMESHGUI()->ResetState(); - erasePreview(); - reject(); -} - - - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::onSelectionDone -// Purpose : SLOT called when selection changed -//======================================================================= -void SMESHGUI_MeshPatternDlg::onSelectionDone() -{ - try - { - if ( mySelection->IObjectCount() != 1 ) - return; - - if ( mySelInput == Mesh ) - { - // Retrieve mesh from selection - Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject(); - SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface( anIO ); - if ( aMesh->_is_nil() ) - return; - - // Get geom object corresponding to the mesh - SALOMEDS::Study_var aStudy = - SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getStudyDocument(); - - SALOMEDS::SObject_var aSO = SMESH::FindSObject( aMesh.in() ); - if ( aSO->_is_nil() ) - return; - - bool isFound = false; - SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( aSO ); - for( ; anIter->More(); anIter->Next() ) - { - SALOMEDS::SObject_var aSO = anIter->Value(); - SALOMEDS::SObject_var aRefSO; - - GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow( - aSO->ReferencedObject( aRefSO )? aRefSO->GetObject() : aSO->GetObject() ); - - if ( !aMeshShape->_is_nil() ) - { - isFound = true; - myMeshShape = aMeshShape; - break; - - } - } - - if ( !isFound ) - return; - - // Clear fields of geom objects if mesh was changed - if ( myMesh != aMesh ) - { - for ( int i = Object; i <= Vertex2; i++ ) - { - myGeomObj[ i ] = GEOM::GEOM_Object::_nil(); - mySelEdit[ i ]->setText( "" ); - } - } - - myMesh = aMesh; - - // Set name of mesh in line edit - QString aName; - SMESH::GetNameOfSelectedIObjects( mySelection, aName ); - mySelEdit[ Mesh ]->setText( aName ); - } - else - { - // Get geom object from selection - Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject(); - GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface( anIO ); - if ( anObj->_is_nil() ) - return; - - // Clear fields of vertexes if face or 3d block was changed - if ( anObj != myGeomObj[ mySelInput ] && mySelInput == Object ) - { - for ( int i = Vertex1; i <= Vertex2; i++ ) - { - myGeomObj[ i ] = GEOM::GEOM_Object::_nil(); - mySelEdit[ i ]->setText( "" ); - } - } - - myGeomObj[ mySelInput ] = anObj; - - // Set name of geom object in line edit - QString aName; - SMESH::GetNameOfSelectedIObjects( mySelection, aName ); - mySelEdit[ mySelInput ]->setText( aName ); - } - } - catch( const SALOME::SALOME_Exception& S_ex ) - { - QtCatchCorbaException( S_ex ); - resetSelInput(); - } - catch( ... ) - { - resetSelInput(); - } - - updateWgState(); - displayPreview(); -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::resetSelInput -// Purpose : Reset fields corresponding to the current selection input -//======================================================================= -void SMESHGUI_MeshPatternDlg::resetSelInput() -{ - if ( mySelInput == Mesh ) - { - myMesh = SMESH::SMESH_Mesh::_nil(); - myMeshShape = GEOM::GEOM_Object::_nil(); - } - - else - myGeomObj[ mySelInput ] = GEOM::GEOM_Object::_nil(); - - mySelEdit[ mySelInput ]->setText( "" ); -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::onDeactivate -// Purpose : SLOT called when dialog must be deativated -//======================================================================= -void SMESHGUI_MeshPatternDlg::onDeactivate() -{ - mySelection->ClearFilters(); - //if ( myReverseChk->isChecked() ) - // erasePreview(); - disconnect( mySelection, 0, this, 0 ); - setEnabled( false ); -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::enterEvent -// Purpose : Event filter -//======================================================================= -void SMESHGUI_MeshPatternDlg::enterEvent( QEvent* ) -{ - if ( myIsCreateDlgOpen ) - return; - - if ( myReverseChk->isChecked() ) - displayPreview(); - SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog() ; - setEnabled( true ); - activateSelection(); - connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) ); -} - - -//================================================================================= -// function : closeEvent() -// purpose : -//================================================================================= -void SMESHGUI_MeshPatternDlg::closeEvent( QCloseEvent* e ) -{ - onClose() ; -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::onSelInputChanged -// Purpose : SLOT. Called when -> button clicked. -// Change current selection input field -//======================================================================= -void SMESHGUI_MeshPatternDlg::onSelInputChanged() -{ - const QObject* aSender = sender(); - for ( int i = Mesh; i <= Vertex2; i++ ) - if ( aSender == mySelBtn[ i ] ) - mySelInput = i; - - activateSelection(); - onSelectionDone(); -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::prepareFilters -// Purpose : Prepare filters for dialog -//======================================================================= - -QStringList SMESHGUI_MeshPatternDlg::prepareFilters() const -{ - static QStringList aList; - if ( aList.isEmpty() ) - { - aList.append( tr( "PATTERN_FILT" ) ); - //aList.append( tr( "ALL_FILES_FILTER" ) ); - } - - return aList; -} - -//================================================================ - -// Function : SMESHGUI_MeshPatternDlg::autoExtension -// Purpose : Append extension to the file name -//================================================================ -QString SMESHGUI_MeshPatternDlg::autoExtension( const QString& theFileName ) const -{ - QString anExt = theFileName.section( '.', -1 ); - return anExt != "smp" && anExt != "SMP" ? theFileName + ".smp" : theFileName; -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::onOpen -// Purpose : SLOT. Called when "Open" button clicked. -// Displays file open dialog -//======================================================================= -void SMESHGUI_MeshPatternDlg::onOpen() -{ - QAD_FileDlg* aDlg = new QAD_FileDlg( this, true ); - aDlg->setCaption( tr( "LOAD_PATTERN" ) ); - aDlg->setMode( QFileDialogP::ExistingFile ); - aDlg->setFilters( prepareFilters() ); - if ( myName->text() != "" ) - aDlg->setSelection( myName->text() + ".smp" ); - QPushButton* anOkBtn = ( QPushButton* )aDlg->child( "OK", "QPushButton" ); - if ( anOkBtn != 0 ) - anOkBtn->setText( tr( "SMESH_BUT_OK" ) ); - - if ( aDlg->exec() != Accepted ) - return; - - QString fName = aDlg->selectedFile(); - if ( fName.isEmpty() ) - return; - - if ( QFileInfo( fName ).extension().isEmpty() ) - fName = autoExtension( fName ); - - fName = QDir::convertSeparators( fName ); - - QString prev = QDir::convertSeparators( myName->text() ); - if ( prev == fName ) - return; - - // Read string from file - QFile aFile( fName ); - if ( !aFile.open( IO_ReadOnly ) ) - { - QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(), - tr( "SMESH_ERROR" ), tr( "ERROR_OF_OPENING" ), QMessageBox::Ok ); - return; - } - - QByteArray aDataArray = aFile.readAll(); - const char* aData = aDataArray.data(); - if ( aData == 0 ) - { - QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(), - tr( "SMESH_ERROR" ), tr( "ERROR_OF_READING" ), QMessageBox::Ok ); - return; - } - - if ( loadFromFile( aData ) ) - myName->setText( QFileInfo( fName ).baseName() ); - - updateWgState(); - displayPreview(); -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::onCloseCreationDlg -// Purpose : SLOT. Called when "Pattern creation" dialog closed with "Close" -//======================================================================= -void SMESHGUI_MeshPatternDlg::onCloseCreationDlg() -{ - setEnabled( true ); - myIsCreateDlgOpen = false; -} - - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::onOkCreationDlg -// Purpose : SLOT. Called when "Pattern creation" dialog closed with OK -// or SAVE buttons. Initialize myPattern field. Redisplay preview -//======================================================================= -void SMESHGUI_MeshPatternDlg::onOkCreationDlg() -{ - myPattern = SMESH::SMESH_Pattern::_duplicate( myCreationDlg->GetPattern() ); - myName->setText( myCreationDlg->GetPatternName() ); - displayPreview(); - setEnabled( true ); - myIsCreateDlgOpen = false; -} - - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::onNew -// Purpose : SLOT. Called when "New..." button clicked. Create new pattern -//======================================================================= -void SMESHGUI_MeshPatternDlg::onNew() -{ - setEnabled( false ); - myIsCreateDlgOpen = true; - if ( myCreationDlg == 0 ) - { - myCreationDlg = new SMESHGUI_CreatePatternDlg( this, mySelection, myType ); - connect( myCreationDlg, SIGNAL( NewPattern() ), SLOT( onOkCreationDlg() ) ); - connect( myCreationDlg, SIGNAL( Close() ), SLOT( onCloseCreationDlg() ) ); - } - else - myCreationDlg->Init( mySelection, myType ); - - myCreationDlg->SetMesh( myMesh ); - myCreationDlg->show(); -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::onReverse -// Purpose : SLOT. Called when state of "Reverse order..." checkbox chaged -// Calculate new points of the mesh to be created. Redisplay preview -//======================================================================= -void SMESHGUI_MeshPatternDlg::onReverse( bool ) -{ - displayPreview(); -} - -//======================================================================= - -// name : SMESHGUI_MeshPatternDlg::onPreview -// Purpose : SLOT. Called when state of "Preview" checkbox changed -// Display/Erase preview -//======================================================================= -void SMESHGUI_MeshPatternDlg::onPreview( bool ) -{ - displayPreview(); -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::displayPreview -// Purpose : Display preview -//======================================================================= -void SMESHGUI_MeshPatternDlg::displayPreview() -{ - try - { - // Redisplay preview in dialog - - SMESH::point_array_var pnts = myPattern->GetPoints(); - SMESH::long_array_var keyPoints = myPattern->GetKeyPoints(); - SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints(); - - if ( pnts->length() == 0 || - keyPoints->length() == 0 || - elemPoints->length() == 0 ) - { - erasePreview(); - return; - } - - else - { - PointVector aPoints( pnts->length() ); - QValueVector aKeyPoints( keyPoints->length() ); - ConnectivityVector anElemPoints( elemPoints->length() ); - - for ( int i = 0, n = pnts->length(); i < n; i++ ) - aPoints[ i ] = pnts[ i ]; - - for ( int i2 = 0, n2 = keyPoints->length(); i2 < n2; i2++ ) - aKeyPoints[ i2 ] = keyPoints[ i2 ]; - - for ( int i3 = 0, n3 = elemPoints->length(); i3 < n3; i3++ ) - { - QValueVector aVec( elemPoints[ i3 ].length() ); - for ( int i4 = 0, n4 = elemPoints[ i3 ].length(); i4 < n4; i4++ ) - aVec[ i4 ] = elemPoints[ i3 ][ i4 ]; - - anElemPoints[ i3 ] = aVec; - } - - myPicture2d->SetPoints( aPoints, aKeyPoints, anElemPoints ); - } - - - // Redisplay preview in 3D viewer - - if ( myPreviewActor != 0 ) - { - if ( VTKViewer_ViewFrame* vf = SMESH::GetCurrentVtkView() ) - { - vf->RemoveActor(myPreviewActor); - vf->Repaint(); - } - myPreviewActor->Delete(); - myPreviewActor = 0; - } - - if ( !myPreviewChk->isChecked() || !isValid( false ) ) - return; - - vtkUnstructuredGrid* aGrid = getGrid(); - if ( aGrid == 0 ) - return; - - // Create and display actor - vtkDataSetMapper* aMapper = vtkDataSetMapper::New(); - aMapper->SetInput( aGrid ); - - myPreviewActor = SALOME_Actor::New(); - myPreviewActor->PickableOff(); - myPreviewActor->SetMapper( aMapper ); - - vtkProperty* aProp = vtkProperty::New(); - aProp->SetRepresentationToWireframe(); - aProp->SetColor( 250, 0, 250 ); - if ( SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh ) ) - aProp->SetLineWidth( SMESH::GetFloat( "SMESH:SettingsWidth", 1 ) +1 ); - else - aProp->SetLineWidth( 1 ); - myPreviewActor->SetProperty( aProp ); - - myPreviewActor->SetRepresentation( 3 ); - - SMESH::GetCurrentVtkView()->AddActor( myPreviewActor ); - SMESH::GetCurrentVtkView()->Repaint(); - - aProp->Delete(); - aGrid->Delete(); - } - catch( const SALOME::SALOME_Exception& S_ex ) - { - QtCatchCorbaException( S_ex ); - erasePreview(); - } - catch( ... ) - { - erasePreview(); - } -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::erasePreview -// Purpose : Erase preview -//======================================================================= -void SMESHGUI_MeshPatternDlg::erasePreview() -{ - // Erase preview in 2D viewer - myPicture2d->SetPoints( PointVector(), QValueVector(), ConnectivityVector() ); - - // Erase preview in 3D viewer - if ( myPreviewActor == 0 ) - return; - - - if ( VTKViewer_ViewFrame* vf = SMESH::GetCurrentVtkView() ) - { - vf->RemoveActor(myPreviewActor); - vf->Repaint(); - } - myPreviewActor->Delete(); - myPreviewActor = 0; -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::updateWgState -// Purpose : Enable/disable selection widgets -//======================================================================= -void SMESHGUI_MeshPatternDlg::updateWgState() -{ - if ( myMesh->_is_nil() ) - { - for ( int i = Object; i <= Vertex2; i++ ) - { - mySelBtn [ i ]->setEnabled( false ); - mySelEdit[ i ]->setEnabled( false ); - mySelEdit[ i ]->setText( "" ); - } - } - else - { - mySelBtn [ Object ]->setEnabled( true ); - mySelEdit[ Object ]->setEnabled( true ); - - if ( myGeomObj[ Object ]->_is_nil() ) - { - for ( int i = Vertex1; i <= Vertex2; i++ ) - { - mySelBtn [ i ]->setEnabled( false ); - mySelEdit[ i ]->setEnabled( false ); - mySelEdit[ i ]->setText( "" ); - } - } - else - { - for ( int i = Object; i <= Vertex2; i++ ) - { - mySelBtn [ i ]->setEnabled( true ); - mySelEdit[ i ]->setEnabled( true ); - } - } - } -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::activateSelection -// Purpose : Activate selection in accordance with current selection input -//======================================================================= -void SMESHGUI_MeshPatternDlg::activateSelection() -{ - mySelection->ClearFilters(); - QAD_Application::getDesktop()->SetSelectionMode( ActorSelection ); - - if ( mySelInput == Object && !myMeshShape->_is_nil() ) - { - if ( myType == Type_2d ) - { - if ( myNbPoints > 0 ) - mySelection->AddFilter( new SMESH_NumberFilter( - - "GEOM", TopAbs_VERTEX, myNbPoints, TopAbs_FACE, myMeshShape ) ); - else - mySelection->AddFilter( new SMESH_NumberFilter( - "GEOM", TopAbs_SHAPE, myNbPoints, TopAbs_FACE, myMeshShape ) ); - } - else - { - TColStd_MapOfInteger aTypes; - aTypes.Add( TopAbs_SHELL ); - aTypes.Add( TopAbs_SOLID ); - mySelection->AddFilter( new SMESH_NumberFilter( - "GEOM", TopAbs_FACE, 6, aTypes, myMeshShape, true ) ); - } - } - else if ( ( mySelInput == Vertex1 || mySelInput == Vertex2 ) && !myGeomObj[ Object ]->_is_nil() ) - { - mySelection->AddFilter( new SMESH_NumberFilter( - "GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX, myGeomObj[ Object ] ) ); - } -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::loadFromFile -// Purpose : Load pattern from file -//======================================================================= -bool SMESHGUI_MeshPatternDlg::loadFromFile( const QString& theName ) -{ - try - { - SMESH::SMESH_Pattern_var aPattern = SMESH::GetPattern(); - - if ( !aPattern->LoadFromFile( theName.latin1() ) || - myType == Type_2d && !aPattern->Is2D()) - { - SMESH::SMESH_Pattern::ErrorCode aCode = aPattern->GetErrorCode(); - QString aMess; - if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NB_POINTS ) aMess = tr( "ERR_READ_NB_POINTS" ); - else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_POINT_COORDS ) aMess = tr( "ERR_READ_POINT_COORDS" ); - else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_TOO_FEW_POINTS ) aMess = tr( "ERR_READ_TOO_FEW_POINTS" ); - else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_3D_COORD ) aMess = tr( "ERR_READ_3D_COORD" ); - else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NO_KEYPOINT ) aMess = tr( "ERR_READ_NO_KEYPOINT" ); - else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_INDEX ) aMess = tr( "ERR_READ_BAD_INDEX" ); - else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_ELEM_POINTS ) aMess = tr( "ERR_READ_ELEM_POINTS" ); - else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NO_ELEMS ) aMess = tr( "ERR_READ_NO_ELEMS" ); - else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_KEY_POINT ) aMess = tr( "ERR_READ_BAD_KEY_POINT" ); - else aMess = tr( "ERROR_OF_LOADING" ); - - QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(), - tr( "SMESH_ERROR" ), aMess, QMessageBox::Ok ); - return false; - } - else - { - myPattern = aPattern; - return true; - } - } - catch( const SALOME::SALOME_Exception& S_ex ) - { - QtCatchCorbaException( S_ex ); - QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(), - tr( "SMESH_ERROR" ), tr( "ERROR_OF_LOADING" ), QMessageBox::Ok ); - return false; - } -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::onTypeChanged - -// Purpose : SLOT. Called when pattern type changed. -// Change dialog's look and feel -//======================================================================= -void SMESHGUI_MeshPatternDlg::onTypeChanged( int theType ) -{ - if ( myType == theType ) - return; - - myType = theType; - - myNbPoints = -1; - myGeomObj[ Object ] = GEOM::GEOM_Object::_nil(); - myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil(); - myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil(); - myPattern = SMESH::GetPattern(); - - myName->setText( "" ); - mySelEdit[ Object ]->setText( "" ); - mySelEdit[ Vertex1 ]->setText( "" ); - mySelEdit[ Vertex2 ]->setText( "" ); - - if ( theType == Type_2d ) - { - mySelLbl [ Vertex2 ]->hide(); - mySelBtn [ Vertex2 ]->hide(); - mySelEdit[ Vertex2 ]->hide(); - myReverseChk->show(); - myPicture2d->show(); - myPicture3d->hide(); - mySelLbl[ Object ]->setText( tr( "FACE" ) ); - mySelLbl[ Vertex1 ]->setText( tr( "VERTEX" ) ); - } - else - { - mySelLbl [ Vertex2 ]->show(); - mySelBtn [ Vertex2 ]->show(); - mySelEdit[ Vertex2 ]->show(); - myReverseChk->hide(); - myPicture2d->hide(); - myPicture3d->show(); - mySelLbl[ Object ]->setText( tr( "3D_BLOCK" ) ); - mySelLbl[ Vertex1 ]->setText( tr( "VERTEX1" ) ); - mySelLbl[ Vertex2 ]->setText( tr( "VERTEX2" ) ); - } - - mySelInput = Mesh; - activateSelection(); - updateWgState(); - displayPreview(); -} - -//======================================================================= -// name : SMESHGUI_MeshPatternDlg::getGrid -// Purpose : Get unstructured grid for pattern -//======================================================================= -vtkUnstructuredGrid* SMESHGUI_MeshPatternDlg::getGrid() -{ - try - { - // Get points from pattern - SMESH::point_array_var pnts = myType == Type_2d - ? myPattern->ApplyToFace( myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked() ) - : myPattern->ApplyTo3DBlock( myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ] ); - - SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints(); - - if ( pnts->length() == 0 || elemPoints->length() == 0 ) - return 0; - - - - // to do : to be removed ///////////////////////////////////////////// - -#ifdef DEB_SLN - for ( int i1 = 0, n1 = pnts->length(); i1 < n1; i1++ ) - printf( "%d: %g %g %g\n", i1, pnts[ i1 ].x, pnts[ i1 ].y, pnts[ i1 ].z ); - - printf( "\nELEMENTS : \n" ); - for ( int i2 = 0, n2 = elemPoints->length(); i2 < n2; i2++ ) - { - - printf( "%d: ", i2 ); - for ( int i3 = 0, n3 = elemPoints[ i2 ].length(); i3 < n3; i3++ ) - printf( "%d ", elemPoints[ i2 ][ i3 ] ); - - printf( "\n" ); - - } -#endif - ////////////////////////////////////////////////////////////////////// - - // Calculate number of points used for cell - vtkIdType aNbCells = elemPoints->length(); - vtkIdType aCellsSize = 0; - for ( int i = 0, n = elemPoints->length(); i < n; i++ ) - aCellsSize += elemPoints[ i ].length(); - - // Create unstructured grid and other usefull arrays - vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New(); - - vtkCellArray* aConnectivity = vtkCellArray::New(); - aConnectivity->Allocate( aCellsSize, 0 ); - - vtkPoints* aPoints = vtkPoints::New(); - aPoints->SetNumberOfPoints( pnts->length() ); - - vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); - aCellTypesArray->SetNumberOfComponents( 1 ); - aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() ); - - vtkIdList *anIdList = vtkIdList::New(); - - // Fill array of points - for ( int p = 0, nbPnt = pnts->length(); p < nbPnt; p++ ) - aPoints->SetPoint( p, pnts[ p ].x, pnts[ p ].y, pnts[ p ].z ); - - for ( int e = 0, nbElem = elemPoints->length(); e < nbElem; e++ ) - { - int nbPoints = elemPoints[ e ].length(); - anIdList->SetNumberOfIds( nbPoints ); - for ( int i = 0; i < nbPoints; i++ ) - anIdList->SetId( i, elemPoints[ e ][ i ] ); - - aConnectivity->InsertNextCell( anIdList ); - - if ( nbPoints == 3 ) aCellTypesArray->InsertNextValue( VTK_TRIANGLE ); - else if ( nbPoints == 5 ) aCellTypesArray->InsertNextValue( VTK_PYRAMID ); - else if ( nbPoints == 6 ) aCellTypesArray->InsertNextValue( VTK_WEDGE ); - else if ( nbPoints == 8 ) aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON ); - else if ( nbPoints == 4 && myType == Type_2d ) aCellTypesArray->InsertNextValue( VTK_QUAD ); - else if ( nbPoints == 4 && myType == Type_3d ) aCellTypesArray->InsertNextValue( VTK_TETRA ); - else aCellTypesArray->InsertNextValue( VTK_EMPTY_CELL ); - } - - vtkIntArray* aCellLocationsArray = vtkIntArray::New(); - aCellLocationsArray->SetNumberOfComponents( 1 ); - aCellLocationsArray->SetNumberOfTuples( aNbCells ); - - aConnectivity->InitTraversal(); - for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) - aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); - - aGrid->SetPoints( aPoints ); - aGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); - - aConnectivity->Delete(); - aPoints->Delete(); - aCellTypesArray->Delete(); - anIdList->Delete(); - aCellLocationsArray->Delete(); - - return aGrid; - } - catch( ... ) - { - return 0; - } -} - - - - - - - - - - - - - - - - - - - - +// SMESH SMESHGUI : GUI for SMESH component +// +// 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 : SMESHGUI_MeshPatternDlg.cxx +// Author : Sergey LITONIN +// Module : SMESH + +#include "SMESHGUI_MeshPatternDlg.h" + +#include "QAD_Desktop.h" +#include "QAD_FileDlg.h" + +#include "SMESHGUI_SpinBox.h" +#include "SMESHGUI.h" +#include "SALOME_Selection.h" +#include "SMESH_NumberFilter.hxx" +#include "SMESHGUI_Utils.h" +#include "SMESHGUI_VTKUtils.h" +#include "SMESHGUI_CreatePatternDlg.h" +#include "SMESHGUI_PatternWidget.h" +#include "SMESH_Actor.h" +#include "SALOMEGUI_QtCatchCorbaException.hxx" +#include "VTKViewer_ViewFrame.h" +#include "SMESHGUI_PatternUtils.h" +#include "SMESH_ActorUtils.h" +#include "SMDS_MeshElement.hxx" +#include "SMDS_Mesh.hxx" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define SPACING 5 +#define MARGIN 10 + +/* + Class : SMESHGUI_MeshPatternDlg + Description : Dialog to specify filters for VTK viewer +*/ + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg +// Purpose : Constructor +//======================================================================= +SMESHGUI_MeshPatternDlg::SMESHGUI_MeshPatternDlg( QWidget* theParent, + SALOME_Selection* theSelection, + const char* theName ) +: QDialog( theParent, theName, false, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ), + myBusy( false ) +{ + setCaption( tr( "CAPTION" ) ); + + QVBoxLayout* aDlgLay = new QVBoxLayout( this, MARGIN, SPACING ); + + QFrame* aMainFrame = createMainFrame ( this ); + QFrame* aBtnFrame = createButtonFrame( this ); + + + + + aDlgLay->addWidget( aMainFrame ); + aDlgLay->addWidget( aBtnFrame ); + + aDlgLay->setStretchFactor( aMainFrame, 1 ); + + myCreationDlg = 0; + Init( theSelection ); +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::createMainFrame +// Purpose : Create frame containing dialog's input fields +//======================================================================= +QFrame* SMESHGUI_MeshPatternDlg::createMainFrame( QWidget* theParent ) +{ + QPixmap iconSlct( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) ); + QPixmap icon2d ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_2d" ) ) ); + QPixmap icon3d ( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_3d" ) ) ); + QPixmap iconOpen( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_FILE_OPEN" ) ) ); + + QPixmap iconSample2d( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_2D" ) ) ); + QPixmap iconSample3d( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr( "ICON_PATTERN_SAMPLE_3D" ) ) ); + + QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, theParent ); + aMainGrp->setFrameStyle( QFrame::NoFrame ); + aMainGrp->setInsideMargin( 0 ); + + // Pattern type group + + myTypeGrp = new QButtonGroup( 1, Qt::Vertical, tr( "PATTERN_TYPE" ), aMainGrp ); + mySwitch2d = new QRadioButton( myTypeGrp ); + mySwitch3d = new QRadioButton( myTypeGrp ); + mySwitch2d->setPixmap( icon2d ); + mySwitch3d->setPixmap( icon3d ); + myTypeGrp->insert( mySwitch2d, Type_2d ); + myTypeGrp->insert( mySwitch3d, Type_3d ); + + + // Mesh group + + QGroupBox* aMeshGrp = new QGroupBox( 1, Qt::Vertical, tr( "SMESH_MESH" ), aMainGrp ); + new QLabel( tr( "SMESH_MESH" ), aMeshGrp ); + mySelBtn[ Mesh ] = new QPushButton( aMeshGrp ); + mySelBtn[ Mesh ]->setPixmap( iconSlct ); + mySelEdit[ Mesh ] = new QLineEdit( aMeshGrp ); + mySelEdit[ Mesh ]->setReadOnly( true ); + + // Pattern group + + QGroupBox* aPatGrp = new QGroupBox( 1, Qt::Horizontal, tr( "PATTERN" ), aMainGrp ); + + // pattern name + QGroupBox* aNameGrp = new QGroupBox( 1, Qt::Vertical, aPatGrp ); + aNameGrp->setFrameStyle( QFrame::NoFrame ); + aNameGrp->setInsideMargin( 0 ); + new QLabel( tr( "PATTERN" ), aNameGrp ); + myName = new QLineEdit( aNameGrp ); + myName->setReadOnly( true ); + myOpenBtn = new QPushButton( aNameGrp ); + myOpenBtn->setPixmap( iconOpen ); + myNewBtn = new QPushButton( tr( "NEW" ), aNameGrp ); + + // Mode selection check box + myRefine = new QCheckBox( tr( "REFINE" ), aPatGrp ); + + // selection widgets for Apply to geom mode + myGeomGrp = new QGroupBox( 3, Qt::Horizontal, aPatGrp ); + myGeomGrp->setFrameStyle( QFrame::NoFrame ); + myGeomGrp->setInsideMargin( 0 ); + + for ( int i = Object; i <= Vertex2; i++ ) + { + mySelLbl[ i ] = new QLabel( myGeomGrp ); + mySelBtn[ i ] = new QPushButton( myGeomGrp ); + mySelBtn[ i ]->setPixmap( iconSlct ); + mySelEdit[ i ] = new QLineEdit( myGeomGrp ); + mySelEdit[ i ]->setReadOnly( true ); + } + + // Widgets for refinement of existing mesh elements + myRefineGrp = new QFrame( aPatGrp ); + myRefineGrp->setFrameStyle( QFrame::NoFrame ); + QGridLayout* aRefGrid = new QGridLayout( myRefineGrp, 3, 3, 0, 5 ); + + mySelLbl[ Ids ] = new QLabel( myRefineGrp ); + mySelBtn[ Ids ] = new QPushButton( myRefineGrp ); + mySelBtn[ Ids ]->setPixmap( iconSlct ); + mySelEdit[ Ids ] = new QLineEdit( myRefineGrp ); + + QLabel* aNodeLbl = new QLabel( tr( "NODE_1" ), myRefineGrp ); + myNode1 = new QSpinBox( myRefineGrp ); + myNode2Lbl = new QLabel( tr( "NODE_2" ), myRefineGrp ); + myNode2 = new QSpinBox( myRefineGrp ); + + aRefGrid->addWidget( mySelLbl [ Ids ], 0, 0 ); + aRefGrid->addWidget( mySelBtn [ Ids ], 0, 1 ); + aRefGrid->addWidget( mySelEdit[ Ids ], 0, 2 ); + aRefGrid->addWidget( aNodeLbl, 1, 0 ); + aRefGrid->addMultiCellWidget( myNode1, 1, 1, 1, 2 ); + aRefGrid->addWidget( myNode2Lbl, 2, 0 ); + aRefGrid->addMultiCellWidget( myNode2, 2, 2, 1, 2 ); + + // reverse check box + myReverseChk = new QCheckBox( tr( "REVERSE" ), aPatGrp ); + + // Pictures 2d and 3d + for ( int i = 0; i < 2; i++ ) + { + if ( i == 0 ) + { + myPicture2d = new SMESHGUI_PatternWidget( aPatGrp ), + myPicture2d->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); + } + else + { + myPicture3d = new QFrame( aPatGrp ), + myPreview3d = new QLabel( myPicture3d ); + myPreview3d->setPixmap( iconSample3d ); + QGridLayout* aLay = new QGridLayout( myPicture3d, 3, 3, 0, 0 ); + QSpacerItem* aSpacerH1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ); + QSpacerItem* aSpacerH2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ); + QSpacerItem* aSpacerV1 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding ); + QSpacerItem* aSpacerV2 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding ); + aLay->addItem( aSpacerH1, 1, 0 ); + aLay->addItem( aSpacerH2, 1, 2 ); + aLay->addItem( aSpacerV1, 0, 1 ); + aLay->addItem( aSpacerV2, 2, 1 ); + aLay->addWidget( myPreview3d, 1, 1 ); + } + } + + myPreviewChk = new QCheckBox( tr( "PREVIEW" ), aPatGrp ); + + // Connect signals and slots + + connect( myTypeGrp, SIGNAL( clicked( int ) ), SLOT( onTypeChanged( int ) ) ); + connect( myOpenBtn, SIGNAL( clicked() ), SLOT( onOpen() ) ); + connect( myNewBtn, SIGNAL( clicked() ), SLOT( onNew() ) ); + connect( myReverseChk, SIGNAL( toggled( bool ) ), SLOT( onReverse( bool ) ) ); + connect( myPreviewChk, SIGNAL( toggled( bool ) ), SLOT( onPreview( bool ) ) ); + connect( myRefine, SIGNAL( toggled( bool ) ), SLOT( onModeToggled( bool ) ) ); + connect( myNode1, SIGNAL( valueChanged( int ) ), SLOT( onNodeChanged( int ) ) ); + connect( myNode2, SIGNAL( valueChanged( int ) ), SLOT( onNodeChanged( int ) ) ); + connect( mySelEdit[Ids], SIGNAL( textChanged( const QString& ) ), SLOT( onTextChanged( const QString& ) ) ); + + QMap< int, QPushButton* >::iterator anIter; + for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter ) + connect( *anIter, SIGNAL( clicked() ), SLOT( onSelInputChanged() ) ); + + return aMainGrp; +} + +//======================================================================= + +// name : SMESHGUI_MeshPatternDlg::createButtonFrame +// Purpose : Create frame containing buttons +//======================================================================= +QFrame* SMESHGUI_MeshPatternDlg::createButtonFrame( QWidget* theParent ) +{ + QFrame* aFrame = new QFrame( theParent ); + aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken ); + + myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), aFrame ); + myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), aFrame ); + myCloseBtn = new QPushButton( tr( "SMESH_BUT_CLOSE" ), aFrame ); + + QSpacerItem* aSpacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ); + + QHBoxLayout* aLay = new QHBoxLayout( aFrame, MARGIN, SPACING ); + + aLay->addWidget( myOkBtn ); + aLay->addWidget( myApplyBtn ); + aLay->addItem( aSpacer); + aLay->addWidget( myCloseBtn ); + + connect( myOkBtn, SIGNAL( clicked() ), SLOT( onOk() ) ); + connect( myCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) ) ; + connect( myApplyBtn, SIGNAL( clicked() ), SLOT( onApply() ) ); + + return aFrame; +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg +// Purpose : Destructor +//======================================================================= +SMESHGUI_MeshPatternDlg::~SMESHGUI_MeshPatternDlg() +{ +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::Init +// Purpose : Init dialog fields, connect signals and slots, show dialog +//======================================================================= +void SMESHGUI_MeshPatternDlg::Init( SALOME_Selection* theSelection ) +{ + myPattern = SMESH::GetPattern(); + myPreviewActor = 0; + myIsCreateDlgOpen = false; + mySelInput = Mesh; + myType = -1; + myNbPoints = -1; + mySelection = theSelection; + SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI(); + aSMESHGUI->SetActiveDialogBox( ( QDialog* )this ); + myMesh = SMESH::SMESH_Mesh::_nil(); + + myMeshShape = GEOM::GEOM_Object::_nil(); + myGeomObj[ Object ] = GEOM::GEOM_Object::_nil(); + myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil(); + myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil(); + + // selection and SMESHGUI + connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) ); + connect( aSMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( onDeactivate() ) ); + connect( aSMESHGUI, SIGNAL( SignalCloseAllDialogs() ), SLOT( onClose() ) ); + + myTypeGrp->setButton( Type_2d ); + onTypeChanged( Type_2d ); + onModeToggled( isRefine() ); + + updateGeometry(); + + resize( minimumSize() ); + + activateSelection(); + onSelectionDone(); + + int x, y ; + aSMESHGUI->DefineDlgPosition( this, x, y ); + this->move( x, y ); + this->show(); +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::isValid +// Purpose : Verify validity of entry data +//======================================================================= +bool SMESHGUI_MeshPatternDlg::isValid( const bool theMess ) +{ + QValueList ids; + if ( ( isRefine() && ( myMesh->_is_nil() || !getIds( ids ) || getNode( false ) < 0 || myType == Type_3d && ( getNode( true ) < 0 || getNode( false ) == getNode( true ) ) ) ) + || ( !isRefine() && ( myMesh->_is_nil() || myMeshShape->_is_nil() || myGeomObj[ Object ]->_is_nil() || + myGeomObj[ Vertex1 ]->_is_nil() || myType == Type_3d && myGeomObj[ Vertex2 ]->_is_nil() ) ) ) + { + if ( theMess ) + QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(), + tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SMESHGUI_INVALID_PARAMETERS" ), QMessageBox::Ok ); + return false; + } + else + return true; +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::onApply +// Purpose : SLOT called when "Apply" button pressed. +//======================================================================= +bool SMESHGUI_MeshPatternDlg::onApply() +{ + try + { + if ( !isValid() ) + return false; + + erasePreview(); + + if ( isRefine() ) { // Refining existing mesh elements + QValueList ids; + getIds( ids ); + SMESH::long_array_var varIds = new SMESH::long_array(); + varIds->length( ids.count() ); + int i = 0; + for ( QValueList::iterator it = ids.begin(); it != ids.end(); ++it ) + varIds[i++] = *it; + myType == Type_2d + ? myPattern->ApplyToMeshFaces ( myMesh, varIds, getNode( false ), myReverseChk->isChecked() ) + : myPattern->ApplyToHexahedrons( myMesh, varIds, getNode( false ), getNode( true ) ); + } + else { // Applying a pattern to geometrical object + if ( myType == Type_2d ) + myPattern->ApplyToFace( + myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked() ); + else + myPattern->ApplyTo3DBlock( + myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ] ); + } + + if ( myPattern->MakeMesh( myMesh ) ) + { + mySelection->ClearIObjects(); + SMESH::UpdateView(); + SMESHGUI::GetSMESHGUI()->GetActiveStudy()->updateObjBrowser( true ); + return true; + } + else + { + QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(), + tr( "SMESH_ERROR" ), tr( "SMESH_OPERATION_FAILED" ), QMessageBox::Ok ); + return false; + } + } + catch( const SALOME::SALOME_Exception& S_ex ) + { + QtCatchCorbaException( S_ex ); + } + catch( ... ) + { + } + + return false; +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::onOk +// Purpose : SLOT called when "Ok" button pressed. +//======================================================================= +void SMESHGUI_MeshPatternDlg::onOk() +{ + if ( onApply() ) + onClose(); +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::onClose +// Purpose : SLOT called when "Close" button pressed. Close dialog +//======================================================================= +void SMESHGUI_MeshPatternDlg::onClose() +{ + mySelection->ClearFilters(); + SMESH::SetPickable(); + QAD_Application::getDesktop()->SetSelectionMode( ActorSelection ); + disconnect( mySelection, 0, this, 0 ); + disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 ); + SMESHGUI::GetSMESHGUI()->ResetState(); + erasePreview(); + reject(); +} + + + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::onSelectionDone +// Purpose : SLOT called when selection changed +//======================================================================= +void SMESHGUI_MeshPatternDlg::onSelectionDone() +{ + if ( myBusy ) + return; + + try + { + if ( mySelInput == Mesh ) + { + if ( mySelection->IObjectCount() != 1 ) + return; + + // Retrieve mesh from selection + Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject(); + SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface( anIO ); + if ( aMesh->_is_nil() ) + return; + + // Get geom object corresponding to the mesh + SALOMEDS::Study_var aStudy = + SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getStudyDocument(); + + SALOMEDS::SObject_var aSO = SMESH::FindSObject( aMesh.in() ); + if ( aSO->_is_nil() ) + return; + + bool isFound = false; + SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( aSO ); + for( ; anIter->More(); anIter->Next() ) + { + SALOMEDS::SObject_var aSO = anIter->Value(); + SALOMEDS::SObject_var aRefSO; + + GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow( + aSO->ReferencedObject( aRefSO )? aRefSO->GetObject() : aSO->GetObject() ); + + if ( !aMeshShape->_is_nil() ) + { + isFound = true; + myMeshShape = aMeshShape; + break; + + } + } + + if ( !isFound ) + myMeshShape = GEOM::GEOM_Object::_nil(); + + // Clear fields of geom objects if mesh was changed + if ( myMesh != aMesh ) + { + for ( int i = Object; i <= Ids; i++ ) + { + myGeomObj[ i ] = GEOM::GEOM_Object::_nil(); + mySelEdit[ i ]->setText( "" ); + } + } + + myMesh = aMesh; + + // Set name of mesh in line edit + QString aName; + SMESH::GetNameOfSelectedIObjects( mySelection, aName ); + mySelEdit[ Mesh ]->setText( aName ); + } + else if ( mySelInput == Ids ) { + QString anIds; + if ( !SMESH::GetNameOfSelectedElements( mySelection, anIds ) ) + anIds = ""; + + myBusy = true; + mySelEdit[ Ids ]->setText( anIds ); + myBusy = false; + } + else + { + if ( mySelection->IObjectCount() != 1 ) + return; + + // Get geom object from selection + Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject(); + GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface( anIO ); + if ( anObj->_is_nil() ) + return; + + // Clear fields of vertexes if face or 3d block was changed + if ( anObj != myGeomObj[ mySelInput ] && mySelInput == Object ) + { + for ( int i = Vertex1; i <= Vertex2; i++ ) + { + myGeomObj[ i ] = GEOM::GEOM_Object::_nil(); + mySelEdit[ i ]->setText( "" ); + } + } + + myGeomObj[ mySelInput ] = anObj; + + // Set name of geom object in line edit + QString aName; + SMESH::GetNameOfSelectedIObjects( mySelection, aName ); + mySelEdit[ mySelInput ]->setText( aName ); + } + } + catch( const SALOME::SALOME_Exception& S_ex ) + { + QtCatchCorbaException( S_ex ); + resetSelInput(); + } + catch( ... ) + { + resetSelInput(); + } + + updateWgState(); + displayPreview(); +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::resetSelInput +// Purpose : Reset fields corresponding to the current selection input +//======================================================================= +void SMESHGUI_MeshPatternDlg::resetSelInput() +{ + if ( mySelInput == Mesh ) + { + myMesh = SMESH::SMESH_Mesh::_nil(); + myMeshShape = GEOM::GEOM_Object::_nil(); + } + + else + myGeomObj[ mySelInput ] = GEOM::GEOM_Object::_nil(); + + mySelEdit[ mySelInput ]->setText( "" ); +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::onDeactivate +// Purpose : SLOT called when dialog must be deativated +//======================================================================= +void SMESHGUI_MeshPatternDlg::onDeactivate() +{ + mySelection->ClearFilters(); + //if ( myReverseChk->isChecked() ) + // erasePreview(); + disconnect( mySelection, 0, this, 0 ); + setEnabled( false ); +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::enterEvent +// Purpose : Event filter +//======================================================================= +void SMESHGUI_MeshPatternDlg::enterEvent( QEvent* ) +{ + if ( myIsCreateDlgOpen ) + return; + + if ( myReverseChk->isChecked() ) + displayPreview(); + SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog() ; + setEnabled( true ); + activateSelection(); + connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) ); + onTextChanged( mySelEdit[Ids]->text() ); +} + + +//================================================================================= +// function : closeEvent() +// purpose : +//================================================================================= +void SMESHGUI_MeshPatternDlg::closeEvent( QCloseEvent* e ) +{ + onClose() ; +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::onSelInputChanged +// Purpose : SLOT. Called when -> button clicked. +// Change current selection input field +//======================================================================= +void SMESHGUI_MeshPatternDlg::onSelInputChanged() +{ + const QObject* aSender = sender(); + for ( int i = Mesh; i <= Ids; i++ ) + if ( aSender == mySelBtn[ i ] ) + mySelInput = i; + + activateSelection(); + onSelectionDone(); +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::prepareFilters +// Purpose : Prepare filters for dialog +//======================================================================= + +QStringList SMESHGUI_MeshPatternDlg::prepareFilters() const +{ + static QStringList aList; + if ( aList.isEmpty() ) + { + aList.append( tr( "PATTERN_FILT" ) ); + //aList.append( tr( "ALL_FILES_FILTER" ) ); + } + + return aList; +} + +//================================================================ + +// Function : SMESHGUI_MeshPatternDlg::autoExtension +// Purpose : Append extension to the file name +//================================================================ +QString SMESHGUI_MeshPatternDlg::autoExtension( const QString& theFileName ) const +{ + QString anExt = theFileName.section( '.', -1 ); + return anExt != "smp" && anExt != "SMP" ? theFileName + ".smp" : theFileName; +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::onOpen +// Purpose : SLOT. Called when "Open" button clicked. +// Displays file open dialog +//======================================================================= +void SMESHGUI_MeshPatternDlg::onOpen() +{ + QAD_FileDlg* aDlg = new QAD_FileDlg( this, true ); + aDlg->setCaption( tr( "LOAD_PATTERN" ) ); + aDlg->setMode( QFileDialogP::ExistingFile ); + aDlg->setFilters( prepareFilters() ); + if ( myName->text() != "" ) + aDlg->setSelection( myName->text() + ".smp" ); + QPushButton* anOkBtn = ( QPushButton* )aDlg->child( "OK", "QPushButton" ); + if ( anOkBtn != 0 ) + anOkBtn->setText( tr( "SMESH_BUT_OK" ) ); + + if ( aDlg->exec() != Accepted ) + return; + + QString fName = aDlg->selectedFile(); + if ( fName.isEmpty() ) + return; + + if ( QFileInfo( fName ).extension().isEmpty() ) + fName = autoExtension( fName ); + + fName = QDir::convertSeparators( fName ); + + QString prev = QDir::convertSeparators( myName->text() ); + if ( prev == fName ) + return; + + // Read string from file + QFile aFile( fName ); + if ( !aFile.open( IO_ReadOnly ) ) + { + QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(), + tr( "SMESH_ERROR" ), tr( "ERROR_OF_OPENING" ), QMessageBox::Ok ); + return; + } + + QByteArray aDataArray = aFile.readAll(); + const char* aData = aDataArray.data(); + if ( aData == 0 ) + { + QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(), + tr( "SMESH_ERROR" ), tr( "ERROR_OF_READING" ), QMessageBox::Ok ); + return; + } + + if ( loadFromFile( aData ) ) + myName->setText( QFileInfo( fName ).baseName() ); + + updateWgState(); + displayPreview(); +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::onCloseCreationDlg +// Purpose : SLOT. Called when "Pattern creation" dialog closed with "Close" +//======================================================================= +void SMESHGUI_MeshPatternDlg::onCloseCreationDlg() +{ + setEnabled( true ); + myIsCreateDlgOpen = false; +} + + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::onOkCreationDlg +// Purpose : SLOT. Called when "Pattern creation" dialog closed with OK +// or SAVE buttons. Initialize myPattern field. Redisplay preview +//======================================================================= +void SMESHGUI_MeshPatternDlg::onOkCreationDlg() +{ + myPattern = SMESH::SMESH_Pattern::_duplicate( myCreationDlg->GetPattern() ); + myName->setText( myCreationDlg->GetPatternName() ); + displayPreview(); + setEnabled( true ); + myIsCreateDlgOpen = false; +} + + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::onNew +// Purpose : SLOT. Called when "New..." button clicked. Create new pattern +//======================================================================= +void SMESHGUI_MeshPatternDlg::onNew() +{ + setEnabled( false ); + myIsCreateDlgOpen = true; + if ( myCreationDlg == 0 ) + { + myCreationDlg = new SMESHGUI_CreatePatternDlg( this, mySelection, myType ); + connect( myCreationDlg, SIGNAL( NewPattern() ), SLOT( onOkCreationDlg() ) ); + connect( myCreationDlg, SIGNAL( Close() ), SLOT( onCloseCreationDlg() ) ); + } + else + myCreationDlg->Init( mySelection, myType ); + + myCreationDlg->SetMesh( myMesh ); + myCreationDlg->show(); +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::onReverse +// Purpose : SLOT. Called when state of "Reverse order..." checkbox chaged +// Calculate new points of the mesh to be created. Redisplay preview +//======================================================================= +void SMESHGUI_MeshPatternDlg::onReverse( bool ) +{ + displayPreview(); +} + +//======================================================================= + +// name : SMESHGUI_MeshPatternDlg::onPreview +// Purpose : SLOT. Called when state of "Preview" checkbox changed +// Display/Erase preview +//======================================================================= +void SMESHGUI_MeshPatternDlg::onPreview( bool ) +{ + displayPreview(); +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::displayPreview +// Purpose : Display preview +//======================================================================= +void SMESHGUI_MeshPatternDlg::displayPreview() +{ + try + { + // Redisplay preview in dialog + + SMESH::point_array_var pnts = myPattern->GetPoints(); + SMESH::long_array_var keyPoints = myPattern->GetKeyPoints(); + SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints(); + + if ( pnts->length() == 0 || + keyPoints->length() == 0 || + elemPoints->length() == 0 ) + { + erasePreview(); + return; + } + + else + { + PointVector aPoints( pnts->length() ); + QValueVector aKeyPoints( keyPoints->length() ); + ConnectivityVector anElemPoints( elemPoints->length() ); + + for ( int i = 0, n = pnts->length(); i < n; i++ ) + aPoints[ i ] = pnts[ i ]; + + for ( int i2 = 0, n2 = keyPoints->length(); i2 < n2; i2++ ) + aKeyPoints[ i2 ] = keyPoints[ i2 ]; + + for ( int i3 = 0, n3 = elemPoints->length(); i3 < n3; i3++ ) + { + QValueVector aVec( elemPoints[ i3 ].length() ); + for ( int i4 = 0, n4 = elemPoints[ i3 ].length(); i4 < n4; i4++ ) + aVec[ i4 ] = elemPoints[ i3 ][ i4 ]; + + anElemPoints[ i3 ] = aVec; + } + + myPicture2d->SetPoints( aPoints, aKeyPoints, anElemPoints ); + } + + + // Redisplay preview in 3D viewer + + if ( myPreviewActor != 0 ) + { + if ( VTKViewer_ViewFrame* vf = SMESH::GetCurrentVtkView() ) + { + vf->RemoveActor(myPreviewActor); + vf->Repaint(); + } + myPreviewActor->Delete(); + myPreviewActor = 0; + } + + if ( !myPreviewChk->isChecked() || !isValid( false ) ) + return; + + vtkUnstructuredGrid* aGrid = getGrid(); + if ( aGrid == 0 ) + return; + + // Create and display actor + vtkDataSetMapper* aMapper = vtkDataSetMapper::New(); + aMapper->SetInput( aGrid ); + + myPreviewActor = SALOME_Actor::New(); + myPreviewActor->PickableOff(); + myPreviewActor->SetMapper( aMapper ); + + vtkProperty* aProp = vtkProperty::New(); + aProp->SetRepresentationToWireframe(); + aProp->SetColor( 250, 0, 250 ); + if ( SMESH::FindActorByObject( myMesh ) ) + aProp->SetLineWidth( SMESH::GetFloat( "SMESH:SettingsWidth", 1 ) +1 ); + else + aProp->SetLineWidth( 1 ); + myPreviewActor->SetProperty( aProp ); + + myPreviewActor->SetRepresentation( 3 ); + + SMESH::GetCurrentVtkView()->AddActor( myPreviewActor ); + SMESH::GetCurrentVtkView()->Repaint(); + + aProp->Delete(); + aGrid->Delete(); + } + catch( const SALOME::SALOME_Exception& S_ex ) + { + QtCatchCorbaException( S_ex ); + erasePreview(); + } + catch( ... ) + { + erasePreview(); + } +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::erasePreview +// Purpose : Erase preview +//======================================================================= +void SMESHGUI_MeshPatternDlg::erasePreview() +{ + // Erase preview in 2D viewer + myPicture2d->SetPoints( PointVector(), QValueVector(), ConnectivityVector() ); + + // Erase preview in 3D viewer + if ( myPreviewActor == 0 ) + return; + + + if ( VTKViewer_ViewFrame* vf = SMESH::GetCurrentVtkView() ) + { + vf->RemoveActor(myPreviewActor); + vf->Repaint(); + } + myPreviewActor->Delete(); + myPreviewActor = 0; +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::updateWgState +// Purpose : Enable/disable selection widgets +//======================================================================= +void SMESHGUI_MeshPatternDlg::updateWgState() +{ + if ( myMesh->_is_nil() ) + { + for ( int i = Object; i <= Ids; i++ ) + { + mySelBtn [ i ]->setEnabled( false ); + mySelEdit[ i ]->setEnabled( false ); + mySelEdit[ i ]->setText( "" ); + } + myNode1->setEnabled( false ); + myNode2->setEnabled( false ); + myNode1->setRange( 0, 0 ); + myNode2->setRange( 0, 0 ); + } + else + { + mySelBtn [ Object ]->setEnabled( true ); + mySelEdit[ Object ]->setEnabled( true ); + mySelBtn [ Ids ] ->setEnabled( true ); + mySelEdit[ Ids ] ->setEnabled( true ); + + if ( myGeomObj[ Object ]->_is_nil() ) + { + for ( int i = Vertex1; i <= Vertex2; i++ ) + { + mySelBtn [ i ]->setEnabled( false ); + mySelEdit[ i ]->setEnabled( false ); + mySelEdit[ i ]->setText( "" ); + } + } + else + { + for ( int i = Object; i <= Vertex2; i++ ) + { + mySelBtn [ i ]->setEnabled( true ); + mySelEdit[ i ]->setEnabled( true ); + } + } + + QValueList ids; + if ( !CORBA::is_nil( myPattern ) && getIds( ids ) ) { + SMESH::long_array_var keyPoints = myPattern->GetKeyPoints(); + if ( keyPoints->length() ) { + myNode1->setEnabled( true ); + myNode2->setEnabled( true ); + myNode1->setRange( 1, keyPoints->length() ); + myNode2->setRange( 1, keyPoints->length() ); + return; + } + } + + myNode1->setEnabled( false ); + myNode2->setEnabled( false ); + myNode1->setRange( 0, 0 ); + myNode2->setRange( 0, 0 ); + } +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::activateSelection +// Purpose : Activate selection in accordance with current selection input +//======================================================================= +void SMESHGUI_MeshPatternDlg::activateSelection() +{ + mySelection->ClearFilters(); + if ( mySelInput == Ids ) { + SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh ); + if ( anActor ) + SMESH::SetPickable(anActor); + + if ( myType == Type_2d ) + QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true ); + else + QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true ); + } + else { + SMESH::SetPickable(); + QAD_Application::getDesktop()->SetSelectionMode( ActorSelection ); + } + + if ( mySelInput == Object && !myMeshShape->_is_nil() ) + { + if ( myType == Type_2d ) + { + if ( myNbPoints > 0 ) + mySelection->AddFilter( new SMESH_NumberFilter( + + "GEOM", TopAbs_VERTEX, myNbPoints, TopAbs_FACE, myMeshShape ) ); + else + mySelection->AddFilter( new SMESH_NumberFilter( + "GEOM", TopAbs_SHAPE, myNbPoints, TopAbs_FACE, myMeshShape ) ); + } + else + { + TColStd_MapOfInteger aTypes; + aTypes.Add( TopAbs_SHELL ); + aTypes.Add( TopAbs_SOLID ); + mySelection->AddFilter( new SMESH_NumberFilter( + "GEOM", TopAbs_FACE, 6, aTypes, myMeshShape, true ) ); + } + } + else if ( ( mySelInput == Vertex1 || mySelInput == Vertex2 ) && !myGeomObj[ Object ]->_is_nil() ) + { + mySelection->AddFilter( new SMESH_NumberFilter( + "GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX, myGeomObj[ Object ] ) ); + } +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::loadFromFile +// Purpose : Load pattern from file +//======================================================================= +bool SMESHGUI_MeshPatternDlg::loadFromFile( const QString& theName ) +{ + try + { + SMESH::SMESH_Pattern_var aPattern = SMESH::GetPattern(); + + if ( !aPattern->LoadFromFile( theName.latin1() ) || + myType == Type_2d && !aPattern->Is2D()) + { + SMESH::SMESH_Pattern::ErrorCode aCode = aPattern->GetErrorCode(); + QString aMess; + if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NB_POINTS ) aMess = tr( "ERR_READ_NB_POINTS" ); + else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_POINT_COORDS ) aMess = tr( "ERR_READ_POINT_COORDS" ); + else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_TOO_FEW_POINTS ) aMess = tr( "ERR_READ_TOO_FEW_POINTS" ); + else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_3D_COORD ) aMess = tr( "ERR_READ_3D_COORD" ); + else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NO_KEYPOINT ) aMess = tr( "ERR_READ_NO_KEYPOINT" ); + else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_INDEX ) aMess = tr( "ERR_READ_BAD_INDEX" ); + else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_ELEM_POINTS ) aMess = tr( "ERR_READ_ELEM_POINTS" ); + else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_NO_ELEMS ) aMess = tr( "ERR_READ_NO_ELEMS" ); + else if ( aCode == SMESH::SMESH_Pattern::ERR_READ_BAD_KEY_POINT ) aMess = tr( "ERR_READ_BAD_KEY_POINT" ); + else aMess = tr( "ERROR_OF_LOADING" ); + + QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(), + tr( "SMESH_ERROR" ), aMess, QMessageBox::Ok ); + return false; + } + else + { + myPattern = aPattern; + return true; + } + } + catch( const SALOME::SALOME_Exception& S_ex ) + { + QtCatchCorbaException( S_ex ); + QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(), + tr( "SMESH_ERROR" ), tr( "ERROR_OF_LOADING" ), QMessageBox::Ok ); + return false; + } +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::onTypeChanged + +// Purpose : SLOT. Called when pattern type changed. +// Change dialog's look and feel +//======================================================================= +void SMESHGUI_MeshPatternDlg::onTypeChanged( int theType ) +{ + if ( myType == theType ) + return; + + myType = theType; + + myNbPoints = -1; + myGeomObj[ Object ] = GEOM::GEOM_Object::_nil(); + myGeomObj[ Vertex1 ] = GEOM::GEOM_Object::_nil(); + myGeomObj[ Vertex2 ] = GEOM::GEOM_Object::_nil(); + myPattern = SMESH::GetPattern(); + + myName->setText( "" ); + mySelEdit[ Object ]->setText( "" ); + mySelEdit[ Vertex1 ]->setText( "" ); + mySelEdit[ Vertex2 ]->setText( "" ); + mySelEdit[ Ids ] ->setText( "" ); + + if ( theType == Type_2d ) + { + // Geom widgets + mySelLbl [ Vertex2 ]->hide(); + mySelBtn [ Vertex2 ]->hide(); + mySelEdit[ Vertex2 ]->hide(); + myReverseChk->show(); + myPicture2d->show(); + myPicture3d->hide(); + mySelLbl[ Object ]->setText( tr( "FACE" ) ); + mySelLbl[ Vertex1 ]->setText( tr( "VERTEX" ) ); + // Refine widgets + mySelLbl[ Ids ]->setText( tr( "MESH_FACES" ) ); + myNode2Lbl->hide(); + myNode2 ->hide(); + } + else + { + // Geom widgets + mySelLbl [ Vertex2 ]->show(); + mySelBtn [ Vertex2 ]->show(); + mySelEdit[ Vertex2 ]->show(); + myReverseChk->hide(); + myPicture2d->hide(); + myPicture3d->show(); + mySelLbl[ Object ]->setText( tr( "3D_BLOCK" ) ); + mySelLbl[ Vertex1 ]->setText( tr( "VERTEX1" ) ); + mySelLbl[ Vertex2 ]->setText( tr( "VERTEX2" ) ); + // Refine widgets + mySelLbl[ Ids ]->setText( tr( "MESH_VOLUMES" ) ); + myNode2Lbl->show(); + myNode2 ->show(); + } + + mySelInput = Mesh; + activateSelection(); + updateWgState(); + displayPreview(); +} + +//======================================================================= +// name : SMESHGUI_MeshPatternDlg::getGrid +// Purpose : Get unstructured grid for pattern +//======================================================================= +vtkUnstructuredGrid* SMESHGUI_MeshPatternDlg::getGrid() +{ + try + { + // Get points from pattern + SMESH::point_array_var pnts; + QValueList ids; + if ( isRefine() && getIds( ids ) ) { + SMESH::long_array_var varIds = new SMESH::long_array(); + varIds->length( ids.count() ); + int i = 0; + for ( QValueList::iterator it = ids.begin(); it != ids.end(); ++it ) + varIds[i++] = *it; + pnts = myType == Type_2d + ? myPattern->ApplyToMeshFaces ( myMesh, varIds, getNode( false ), myReverseChk->isChecked() ) + : myPattern->ApplyToHexahedrons( myMesh, varIds, getNode( false ), getNode( true ) ); + } + else { + pnts = myType == Type_2d + ? myPattern->ApplyToFace ( myGeomObj[ Object ], myGeomObj[ Vertex1 ], myReverseChk->isChecked() ) + : myPattern->ApplyTo3DBlock( myGeomObj[ Object ], myGeomObj[ Vertex1 ], myGeomObj[ Vertex2 ] ); + } + + SMESH::array_of_long_array_var elemPoints = myPattern->GetElementPoints(); + + if ( pnts->length() == 0 || elemPoints->length() == 0 ) + return 0; + + + + // to do : to be removed ///////////////////////////////////////////// + +#ifdef DEB_SLN + for ( int i1 = 0, n1 = pnts->length(); i1 < n1; i1++ ) + printf( "%d: %g %g %g\n", i1, pnts[ i1 ].x, pnts[ i1 ].y, pnts[ i1 ].z ); + + printf( "\nELEMENTS : \n" ); + for ( int i2 = 0, n2 = elemPoints->length(); i2 < n2; i2++ ) + { + + printf( "%d: ", i2 ); + for ( int i3 = 0, n3 = elemPoints[ i2 ].length(); i3 < n3; i3++ ) + printf( "%d ", elemPoints[ i2 ][ i3 ] ); + + printf( "\n" ); + + } +#endif + ////////////////////////////////////////////////////////////////////// + + // Calculate number of points used for cell + vtkIdType aNbCells = elemPoints->length(); + vtkIdType aCellsSize = 0; + for ( int i = 0, n = elemPoints->length(); i < n; i++ ) + aCellsSize += elemPoints[ i ].length(); + + // Create unstructured grid and other usefull arrays + vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New(); + + vtkCellArray* aConnectivity = vtkCellArray::New(); + aConnectivity->Allocate( aCellsSize, 0 ); + + vtkPoints* aPoints = vtkPoints::New(); + aPoints->SetNumberOfPoints( pnts->length() ); + + vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); + aCellTypesArray->SetNumberOfComponents( 1 ); + aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() ); + + vtkIdList *anIdList = vtkIdList::New(); + + // Fill array of points + for ( int p = 0, nbPnt = pnts->length(); p < nbPnt; p++ ) + aPoints->SetPoint( p, pnts[ p ].x, pnts[ p ].y, pnts[ p ].z ); + + for ( int e = 0, nbElem = elemPoints->length(); e < nbElem; e++ ) + { + int nbPoints = elemPoints[ e ].length(); + anIdList->SetNumberOfIds( nbPoints ); + for ( int i = 0; i < nbPoints; i++ ) + anIdList->SetId( i, elemPoints[ e ][ i ] ); + + aConnectivity->InsertNextCell( anIdList ); + + if ( nbPoints == 3 ) aCellTypesArray->InsertNextValue( VTK_TRIANGLE ); + else if ( nbPoints == 5 ) aCellTypesArray->InsertNextValue( VTK_PYRAMID ); + else if ( nbPoints == 6 ) aCellTypesArray->InsertNextValue( VTK_WEDGE ); + else if ( nbPoints == 8 ) aCellTypesArray->InsertNextValue( VTK_HEXAHEDRON ); + else if ( nbPoints == 4 && myType == Type_2d ) aCellTypesArray->InsertNextValue( VTK_QUAD ); + else if ( nbPoints == 4 && myType == Type_3d ) aCellTypesArray->InsertNextValue( VTK_TETRA ); + else aCellTypesArray->InsertNextValue( VTK_EMPTY_CELL ); + } + + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); + aCellLocationsArray->SetNumberOfComponents( 1 ); + aCellLocationsArray->SetNumberOfTuples( aNbCells ); + + aConnectivity->InitTraversal(); + for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) + aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); + + aGrid->SetPoints( aPoints ); + aGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); + + aConnectivity->Delete(); + aPoints->Delete(); + aCellTypesArray->Delete(); + anIdList->Delete(); + aCellLocationsArray->Delete(); + + return aGrid; + } + catch( ... ) + { + return 0; + } +} + +//======================================================================= +// name : onModeToggled +// Purpose : +//======================================================================= +void SMESHGUI_MeshPatternDlg::onModeToggled( bool on ) +{ + on ? myRefineGrp->show() : myRefineGrp->hide(); + on ? myGeomGrp->hide() : myGeomGrp->show(); +} + +//======================================================================= +// name : isRefine +// Purpose : +//======================================================================= +bool SMESHGUI_MeshPatternDlg::isRefine() const +{ + return myRefine->isChecked(); +} + +//======================================================================= +//function : onTextChanged +//purpose : +//======================================================================= +void SMESHGUI_MeshPatternDlg::onTextChanged(const QString& theNewText) +{ + if ( myBusy || !isRefine() ) + return; + + myBusy = true; + + if ( mySelInput != Ids ) { + mySelInput = Ids; + activateSelection(); + } + + // hilight entered elements/nodes + SMDS_Mesh* aMesh = 0; + SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh ); + if ( anActor ) + aMesh = anActor->GetObject()->GetMesh(); + + if ( aMesh ) { + mySelection->ClearIObjects(); + mySelection->AddIObject( anActor->getIO() ); + + QStringList aListId = QStringList::split( " ", theNewText, false); + + for ( int i = 0; i < aListId.count(); i++ ) { + const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() ); + if ( e && e->GetType() == ( myType == Type_2d ? SMDSAbs_Face : SMDSAbs_Volume ) ) { + if ( !mySelection->IsIndexSelected( anActor->getIO(), e->GetID() ) ) + mySelection->AddOrRemoveIndex( anActor->getIO(), e->GetID(), true ); + } + } + } + + myBusy = false; +} + +//======================================================================= +//function : onNodeChanged +//purpose : +//======================================================================= +void SMESHGUI_MeshPatternDlg::onNodeChanged( int value ) +{ + if ( myType == Type_3d ) { + QSpinBox* first = (QSpinBox*)sender(); + QSpinBox* second = first == myNode1 ? myNode2 : myNode1; + int secondVal = second->value(); + if ( secondVal == value ) { + secondVal = value == second->maxValue() ? second->minValue() : value + 1; + bool blocked = second->signalsBlocked(); + second->blockSignals( true ); + second->setValue( secondVal ); + second->blockSignals( blocked ); + } + } + + displayPreview(); +} + +//======================================================================= +//function : getIds +//purpose : +//======================================================================= +bool SMESHGUI_MeshPatternDlg::getIds( QValueList& ids ) const +{ + ids.clear(); + QStringList strIds = QStringList::split( " ", mySelEdit[Ids]->text() ); + bool isOk; + int val; + for ( QStringList::iterator it = strIds.begin(); it != strIds.end(); ++it ) { + val = (*it).toInt( &isOk ); + if ( isOk ) + ids.append( val ); + } + + return ids.count(); +} + +//======================================================================= +//function : getNode1 +//purpose : +//======================================================================= +int SMESHGUI_MeshPatternDlg::getNode( bool second ) const +{ + return second ? myNode2->value() - 1 : myNode1->value() - 1; +} + diff --git a/src/SMESHGUI/SMESHGUI_MeshPatternDlg.h b/src/SMESHGUI/SMESHGUI_MeshPatternDlg.h index 1c1787b0c..26a733236 100755 --- a/src/SMESHGUI/SMESHGUI_MeshPatternDlg.h +++ b/src/SMESHGUI/SMESHGUI_MeshPatternDlg.h @@ -1,169 +1,187 @@ -// 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 : SMESHGUI_MeshPatternDlg.h -// Author : Sergey LITONIN -// Module : SMESH - - -#ifndef SMESHGUI_MeshPatternDlg_H -#define SMESHGUI_MeshPatternDlg_H - -#include - -// IDL Headers -#include -#include CORBA_SERVER_HEADER(GEOM_Gen) -#include CORBA_SERVER_HEADER(SMESH_Mesh) -#include CORBA_SERVER_HEADER(SMESH_Pattern) - -class QCloseEvent; -class QFrame; -class QLineEdit; -class SMESHGUI_SpinBox; -class QPushButton; -class SALOME_Selection; -class QRadioButton; -class QCheckBox; -class QButtonGroup; -class QLabel; -class SMESHGUI_CreatePatternDlg; -class SMESHGUI_PatternWidget; -class vtkUnstructuredGrid; -class SALOME_Actor; - -/* - Class : SMESHGUI_MeshPatternDlg - Description : Dialog to specify filters for VTK viewer -*/ - -class SMESHGUI_MeshPatternDlg : public QDialog -{ - Q_OBJECT - - // Pattern type - enum { Type_2d, Type_3d }; - - // selection input - enum { Mesh, Object, Vertex1, Vertex2 }; - -public: - SMESHGUI_MeshPatternDlg( QWidget*, - SALOME_Selection*, - const char* = 0 ); - virtual ~SMESHGUI_MeshPatternDlg(); - - void Init( SALOME_Selection* ); - -private slots: - - void onOk(); - bool onApply(); - void onClose(); - - void onDeactivate(); - - void onSelectionDone(); - void onSelInputChanged(); - - void onTypeChanged( int ); - void onOpen(); - void onNew(); - void onReverse( bool ); - void onPreview( bool ); - void onOkCreationDlg(); - void onCloseCreationDlg(); - -private: - - QFrame* createButtonFrame( QWidget* ); - QFrame* createMainFrame ( QWidget* ); - void displayPreview(); - vtkUnstructuredGrid* getGrid(); - void erasePreview(); - void updateWgState(); - bool loadFromFile( const QString& ); - void activateSelection(); - QStringList prepareFilters() const; - QString autoExtension( const QString& theFileName ) const; - void closeEvent( QCloseEvent* e ) ; - void enterEvent ( QEvent * ) ; - bool isValid( const bool theMess = true ); - void resetSelInput(); - -private: - - QPushButton* myOkBtn; - QPushButton* myApplyBtn; - QPushButton* myCloseBtn; - - QButtonGroup* myTypeGrp; - QRadioButton* mySwitch2d; - QRadioButton* mySwitch3d; - - QMap< int, QPushButton* > mySelBtn; - QMap< int, QLineEdit* > mySelEdit; - QMap< int, QLabel* > mySelLbl; - - QLineEdit* myName; - QPushButton* myOpenBtn; - QPushButton* myNewBtn; - - QCheckBox* myReverseChk; - SMESHGUI_PatternWidget* myPicture2d; - QFrame* myPicture3d; - QLabel* myPreview3d; - - QCheckBox* myPreviewChk; - - SALOME_Selection* mySelection; - int mySelInput; - int myNbPoints; - int myType; - bool myIsCreateDlgOpen; - - SMESH::SMESH_Mesh_var myMesh; - GEOM::GEOM_Object_var myMeshShape; - QMap< int, GEOM::GEOM_Object_var > myGeomObj; - - SMESHGUI_CreatePatternDlg* myCreationDlg; - SMESH::SMESH_Pattern_var myPattern; - SALOME_Actor* myPreviewActor; -}; - -#endif - - - - - - - - - - - - - - - - - +// 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 : SMESHGUI_MeshPatternDlg.h +// Author : Sergey LITONIN +// Module : SMESH + + +#ifndef SMESHGUI_MeshPatternDlg_H +#define SMESHGUI_MeshPatternDlg_H + +#include + +// IDL Headers +#include +#include CORBA_SERVER_HEADER(GEOM_Gen) +#include CORBA_SERVER_HEADER(SMESH_Mesh) +#include CORBA_SERVER_HEADER(SMESH_Pattern) + +class QCloseEvent; +class QFrame; +class QLineEdit; +class SMESHGUI_SpinBox; +class QPushButton; +class SALOME_Selection; +class QRadioButton; +class QCheckBox; +class QButtonGroup; +class QLabel; +class QSpinBox; +class QGroupBox; +class SMESHGUI_CreatePatternDlg; +class SMESHGUI_PatternWidget; +class vtkUnstructuredGrid; +class SALOME_Actor; + +/* + Class : SMESHGUI_MeshPatternDlg + Description : Dialog to specify filters for VTK viewer +*/ + +class SMESHGUI_MeshPatternDlg : public QDialog +{ + Q_OBJECT + + // Pattern type + enum { Type_2d, Type_3d }; + + // selection input + enum { Mesh, Object, Vertex1, Vertex2, Ids }; + +public: + SMESHGUI_MeshPatternDlg( QWidget*, + SALOME_Selection*, + const char* = 0 ); + virtual ~SMESHGUI_MeshPatternDlg(); + + void Init( SALOME_Selection* ); + +private slots: + + void onOk(); + bool onApply(); + void onClose(); + + void onDeactivate(); + + void onSelectionDone(); + void onSelInputChanged(); + + void onTypeChanged( int ); + void onModeToggled( bool ); + void onOpen(); + void onNew(); + void onReverse( bool ); + void onPreview( bool ); + void onOkCreationDlg(); + void onCloseCreationDlg(); + void onTextChanged( const QString& ); + void onNodeChanged( int value ); + +private: + + QFrame* createButtonFrame( QWidget* ); + QFrame* createMainFrame ( QWidget* ); + void displayPreview(); + vtkUnstructuredGrid* getGrid(); + void erasePreview(); + void updateWgState(); + bool loadFromFile( const QString& ); + void activateSelection(); + QStringList prepareFilters() const; + QString autoExtension( const QString& theFileName ) const; + void closeEvent( QCloseEvent* e ) ; + void enterEvent ( QEvent * ) ; + bool isValid( const bool theMess = true ); + void resetSelInput(); + bool isRefine() const; + + bool getIds( QValueList& ) const; + int getNode( bool = false ) const; + +private: + + QPushButton* myOkBtn; + QPushButton* myApplyBtn; + QPushButton* myCloseBtn; + + QButtonGroup* myTypeGrp; + QRadioButton* mySwitch2d; + QRadioButton* mySwitch3d; + + QCheckBox* myRefine; + + QFrame* myRefineGrp; + QSpinBox* myNode1; + QSpinBox* myNode2; + QLabel* myNode2Lbl; + + QGroupBox* myGeomGrp; + QMap< int, QPushButton* > mySelBtn; + QMap< int, QLineEdit* > mySelEdit; + QMap< int, QLabel* > mySelLbl; + + QLineEdit* myName; + QPushButton* myOpenBtn; + QPushButton* myNewBtn; + + QCheckBox* myReverseChk; + SMESHGUI_PatternWidget* myPicture2d; + QFrame* myPicture3d; + QLabel* myPreview3d; + + QCheckBox* myPreviewChk; + + SALOME_Selection* mySelection; + int mySelInput; + int myNbPoints; + int myType; + bool myIsCreateDlgOpen; + bool myBusy; + + SMESH::SMESH_Mesh_var myMesh; + GEOM::GEOM_Object_var myMeshShape; + QMap< int, GEOM::GEOM_Object_var > myGeomObj; + + SMESHGUI_CreatePatternDlg* myCreationDlg; + SMESH::SMESH_Pattern_var myPattern; + SALOME_Actor* myPreviewActor; +}; + +#endif + + + + + + + + + + + + + + + + + diff --git a/src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx b/src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx index da81e169e..b1662d8e6 100755 --- a/src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx @@ -70,6 +70,10 @@ #include #include +// IDL Headers +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SMESH_Group) + #define SPACING 5 #define MARGIN 10 @@ -152,11 +156,13 @@ QFrame* SMESHGUI_MultiEditDlg::createMainFrame( QWidget* theParent ) mySubmeshChk = new QCheckBox( tr( "SMESH_SUBMESH" ), aGrp ); mySubmeshBtn = new QPushButton( aGrp ); mySubmesh = new QLineEdit( aGrp ); + mySubmesh->setReadOnly( true ); mySubmeshBtn->setPixmap( aPix ); myGroupChk = new QCheckBox( tr( "GROUP" ), aGrp ); myGroupBtn = new QPushButton( aGrp ); myGroup = new QLineEdit( aGrp ); + myGroup->setReadOnly( true ); myGroupBtn->setPixmap( aPix ); return aMainGrp; diff --git a/src/SMESHGUI/SMESHGUI_NodesDlg.cxx b/src/SMESHGUI/SMESHGUI_NodesDlg.cxx index 872c2015f..67b0daa23 100644 --- a/src/SMESHGUI/SMESHGUI_NodesDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_NodesDlg.cxx @@ -46,6 +46,8 @@ #include "QAD_MessageBox.h" #include "SMESH_Actor.h" +#include "SMESH_ObjectDef.h" + #include "SMDS_Mesh.hxx" #include "SMDS_MeshNode.hxx" diff --git a/src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.cxx b/src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.cxx index b55413f09..c2474d067 100644 --- a/src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.cxx @@ -602,7 +602,6 @@ void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged() myActor = anActor; vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor(); - double aMin = 0.0, aMax = 0.0; if ( myScalarBarActor->GetLookupTable() ) { float *range = myScalarBarActor->GetLookupTable()->GetRange(); myMinEdit->setText( QString::number( range[0] ) ); diff --git a/src/SMESHGUI/SMESHGUI_RenumberingDlg.cxx b/src/SMESHGUI/SMESHGUI_RenumberingDlg.cxx index 35b9df5ef..00ede0b48 100644 --- a/src/SMESHGUI/SMESHGUI_RenumberingDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_RenumberingDlg.cxx @@ -246,7 +246,6 @@ void SMESHGUI_RenumberingDlg::ClickOnApply() if ( !myMesh->_is_nil()) { - bool aResult = false; try { SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); diff --git a/src/SMESHGUI/SMESHGUI_RevolutionDlg.cxx b/src/SMESHGUI/SMESHGUI_RevolutionDlg.cxx index 9b7be8bb4..f7782b57d 100644 --- a/src/SMESHGUI/SMESHGUI_RevolutionDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_RevolutionDlg.cxx @@ -56,6 +56,10 @@ #include #include +// IDL Headers +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SMESH_Group) + using namespace std; //================================================================================= diff --git a/src/SMESHGUI/SMESHGUI_RotationDlg.cxx b/src/SMESHGUI/SMESHGUI_RotationDlg.cxx index a060d034a..fd7253b76 100644 --- a/src/SMESHGUI/SMESHGUI_RotationDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_RotationDlg.cxx @@ -55,6 +55,10 @@ #include #include +// IDL Headers +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SMESH_Group) + using namespace std; //================================================================================= diff --git a/src/SMESHGUI/SMESHGUI_SmoothingDlg.cxx b/src/SMESHGUI/SMESHGUI_SmoothingDlg.cxx index dbbdfd30b..3099baeb0 100644 --- a/src/SMESHGUI/SMESHGUI_SmoothingDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_SmoothingDlg.cxx @@ -58,6 +58,10 @@ #include #include +// IDL Headers +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SMESH_Group) + using namespace std; //================================================================================= diff --git a/src/SMESHGUI/SMESHGUI_SpinBox.h b/src/SMESHGUI/SMESHGUI_SpinBox.h index 4fdf10e86..fab8312d2 100644 --- a/src/SMESHGUI/SMESHGUI_SpinBox.h +++ b/src/SMESHGUI/SMESHGUI_SpinBox.h @@ -44,16 +44,17 @@ public : SMESHGUI_SpinBox( QWidget* parent, const char* name = 0 ) ; ~SMESHGUI_SpinBox() ; - void RangeStepAndValidator( double min = -1000000.0, - double max = +1000000.0, - double step = 100.0, - unsigned short decimals = 3 ) ; - void SetValue( double v ) ; - double GetValue() ; - QString GetString() ; + void RangeStepAndValidator( double min = -1000000.0, + double max = +1000000.0, + double step = 100.0, + unsigned short decimals = 3 ) ; + void SetValue( double v ) ; + double GetValue() ; + QString GetString() ; + QLineEdit* editor() { return QAD_SpinBoxDbl::editor(); } public slots: - void SetStep( double newStep ); + void SetStep( double newStep ); }; #endif // SMESHSPINBOX_H diff --git a/src/SMESHGUI/SMESHGUI_SymmetryDlg.cxx b/src/SMESHGUI/SMESHGUI_SymmetryDlg.cxx index 31a92ef23..1186ce9d4 100644 --- a/src/SMESHGUI/SMESHGUI_SymmetryDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_SymmetryDlg.cxx @@ -55,6 +55,10 @@ #include #include +// IDL Headers +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SMESH_Group) + using namespace std; //================================================================================= diff --git a/src/SMESHGUI/SMESHGUI_TranslationDlg.cxx b/src/SMESHGUI/SMESHGUI_TranslationDlg.cxx index 641ec5c7b..0bb568609 100644 --- a/src/SMESHGUI/SMESHGUI_TranslationDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_TranslationDlg.cxx @@ -56,6 +56,10 @@ #include #include +// IDL Headers +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SMESH_Group) + using namespace std; //================================================================================= diff --git a/src/SMESHGUI/SMESHGUI_VTKUtils.cxx b/src/SMESHGUI/SMESHGUI_VTKUtils.cxx index 42e6db261..15a7be039 100644 --- a/src/SMESHGUI/SMESHGUI_VTKUtils.cxx +++ b/src/SMESHGUI/SMESHGUI_VTKUtils.cxx @@ -50,6 +50,7 @@ #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes) #include "SMESH_Actor.h" +#include "SMESH_ObjectDef.h" using namespace std; @@ -155,6 +156,19 @@ namespace SMESH{ } + void RepaintViewFrame(VTKViewer_ViewFrame* theFrame) + { + theFrame->Repaint(); + } + + + void RenderViewFrame(VTKViewer_ViewFrame* theFrame) + { + theFrame->getRW()->getRenderWindow()->Render(); + theFrame->Repaint(); + } + + SMESH_Actor* FindActorByEntry(QAD_StudyFrame *theStudyFrame, const char* theEntry) { @@ -506,7 +520,7 @@ namespace SMESH{ { theName = ""; if(theIO->hasEntry()){ - if(SMESH_Actor *anActor = FindActorByEntry(theIO->getEntry())){ + if(FindActorByEntry(theIO->getEntry())){ TColStd_IndexedMapOfInteger aMapIndex; theSel->GetIndex(theIO,aMapIndex); for(int i = 1; i <= aMapIndex.Extent(); i++){ @@ -535,7 +549,7 @@ namespace SMESH{ { theName = ""; if(theIO->hasEntry()){ - if(SMESH_Actor *anActor = FindActorByEntry(theIO->getEntry())){ + if(FindActorByEntry(theIO->getEntry())){ TColStd_IndexedMapOfInteger aMapIndex; theSel->GetIndex(theIO,aMapIndex); typedef std::set TIdContainer; diff --git a/src/SMESHGUI/SMESHGUI_VTKUtils.h b/src/SMESHGUI/SMESHGUI_VTKUtils.h index 9937073b6..a2732f703 100644 --- a/src/SMESHGUI/SMESHGUI_VTKUtils.h +++ b/src/SMESHGUI/SMESHGUI_VTKUtils.h @@ -63,6 +63,9 @@ namespace SMESH{ VTKViewer_ViewFrame* GetCurrentVtkView(); + void RepaintViewFrame(VTKViewer_ViewFrame* theFrame); + + void RenderViewFrame(VTKViewer_ViewFrame* theFrame); //---------------------------------------------------------------------------- SMESH_Actor* FindActorByEntry(QAD_StudyFrame *theStudyFrame, diff --git a/src/SMESHGUI/SMESH_icons.po b/src/SMESHGUI/SMESH_icons.po index 1cb8085b2..60dff5a19 100644 --- a/src/SMESHGUI/SMESH_icons.po +++ b/src/SMESHGUI/SMESH_icons.po @@ -211,27 +211,12 @@ msgstr "pattern_sample_2d.png" msgid "ICON_PATTERN_SAMPLE_3D" msgstr "pattern_sample_3D.png" +#----------------------------------------------------------- +# Add/Remove buttons +#----------------------------------------------------------- +msgid "ICON_APPEND" +msgstr "mesh_add.png" - - - - - - - - - - - - - - - - - - - - - - +msgid "ICON_REMOVE" +msgstr "mesh_remove.png" \ No newline at end of file diff --git a/src/SMESHGUI/SMESH_msg_en.po b/src/SMESHGUI/SMESH_msg_en.po index 8a0a4163b..b4d314640 100644 --- a/src/SMESHGUI/SMESH_msg_en.po +++ b/src/SMESHGUI/SMESH_msg_en.po @@ -961,12 +961,21 @@ msgstr "Free borders" msgid "SMESHGUI_FilterTable::MULTI_BORDERS" msgstr "Borders at multi-connections" +#msgid "SMESHGUI_FilterTable::MULTI2D_BORDERS" +#msgstr "Borders at multi-connections 2D" + msgid "SMESHGUI_FilterTable::LENGTH" msgstr "Length" +#msgid "SMESHGUI_FilterTable::LENGTH2D" +#msgstr "Length2D" + msgid "SMESHGUI_FilterTable::ASPECT_RATIO" msgstr "Aspect ratio" +msgid "SMESHGUI_FilterTable::ASPECT_RATIO_3D" +msgstr "Aspect ratio 3D" + msgid "SMESHGUI_FilterTable::WARPING" msgstr "Warping" @@ -1039,6 +1048,9 @@ msgstr "Belong to Plane" msgid "SMESHGUI_FilterTable::BELONG_TO_CYLINDER" msgstr "Belong to Cylinder" +msgid "SMESHGUI_FilterTable::LYING_ON_GEOM" +msgstr "Lying on Geom" + # -------------- SMESHGUI_FilterDlg -------------- msgid "SMESHGUI_FilterDlg::TLT" msgstr "Selection filter" @@ -1092,11 +1104,17 @@ msgstr "This command is available in VTK viewer only\nPlease, create VTK viewer msgid "LENGTH_EDGES" msgstr "Length" +msgid "LENGTH2D_EDGES" +msgstr "Length 2D" + msgid "FREE_BORDERS" -msgstr "Free borders" +msgstr "Free Borders" msgid "MULTI_BORDERS" -msgstr "Borders at multi-connections" +msgstr "Borders at Multi-Connections" + +msgid "MULTI2D_BORDERS" +msgstr "Borders at Multi-Connections 2D" msgid "AREA_ELEMENTS" msgstr "Area" @@ -1107,6 +1125,9 @@ msgstr "Taper" msgid "ASPECTRATIO_ELEMENTS" msgstr "Aspect Ratio" +msgid "ASPECTRATIO_3D_ELEMENTS" +msgstr "Aspect Ratio 3D" + msgid "MINIMUMANGLE_ELEMENTS" msgstr "Minimum Angle" @@ -1414,7 +1435,6 @@ msgstr "Centroidal" msgid "SMESHGUI_ExtrusionDlg::EXTRUSION_ALONG_LINE" msgstr "Extrusion along a line" - msgid "SMESHGUI_ExtrusionDlg::EXTRUSION_1D" msgstr "Extrusion of 1D elements" @@ -1423,6 +1443,41 @@ msgstr "Extrusion of 2D elements" #---------------------------------------------------- +msgid "SMESHGUI_ExtrusionAlongPathDlg::EXTRUSION_ALONG_PATH" +msgstr "Extrusion along a path" + +msgid "SMESHGUI_ExtrusionAlongPathDlg::EXTRUSION_1D" +msgstr "Extrusion of 1D elements" + +msgid "SMESHGUI_ExtrusionAlongPathDlg::EXTRUSION_2D" +msgstr "Extrusion of 2D elements" + +msgid "SMESHGUI_ExtrusionAlongPathDlg::SMESH_PATH" +msgstr "Path" + +msgid "SMESHGUI_ExtrusionAlongPathDlg::SMESH_PATH_MESH" +msgstr "Mesh" + +msgid "SMESHGUI_ExtrusionAlongPathDlg::SMESH_PATH_SHAPE" +msgstr "Shape (edge or wire)" + +msgid "SMESHGUI_ExtrusionAlongPathDlg::SMESH_PATH_START" +msgstr "Start point" + +msgid "SMESHGUI_ExtrusionAlongPathDlg::SMESH_USE_ANGLES" +msgstr "Use Angles" + +msgid "SMESHGUI_ExtrusionAlongPathDlg::SMESH_ANGLES" +msgstr "Angles" + +msgid "SMESHGUI_ExtrusionAlongPathDlg::SMESH_USE_BASE_POINT" +msgstr "Use Base Point" + +msgid "SMESHGUI_ExtrusionAlongPathDlg::SMESH_BASE_POINT" +msgstr "Base Point" + +#---------------------------------------------------- + msgid "SMESHGUI_RevolutionDlg::REVOLUTION_AROUND_AXIS" msgstr "Revolution around an axis" @@ -1605,6 +1660,20 @@ msgstr "It is impossible to load pattern\nThere are no elements in it" msgid "SMESHGUI_MeshPatternDlg::ERR_READ_BAD_KEY_POINT" msgstr "It is impossible to load pattern\nKey-point not on a boundary" +msgid "SMESHGUI_MeshPatternDlg::REFINE" +msgstr "Refine selected mesh elements" + +msgid "SMESHGUI_MeshPatternDlg::NODE_1" +msgstr "Node 1" + +msgid "SMESHGUI_MeshPatternDlg::NODE_2" +msgstr "Node 2" + +msgid "SMESHGUI_MeshPatternDlg::MESH_FACES" +msgstr "Mesh faces" + +msgid "SMESHGUI_MeshPatternDlg::MESH_VOLUMES" +msgstr "Mesh volumes" #---------------------------------------------------- diff --git a/src/SMESH_I/Makefile.in b/src/SMESH_I/Makefile.in index 2517d100f..5a5457f9e 100644 --- a/src/SMESH_I/Makefile.in +++ b/src/SMESH_I/Makefile.in @@ -47,7 +47,7 @@ EXPORT_HEADERS= \ SMESH_Hypothesis_i.hxx \ SMESH.hxx -EXPORT_PYSCRIPTS = smeshpy.py SMESH_test.py +EXPORT_PYSCRIPTS = smeshpy.py # Libraries targets @@ -82,9 +82,9 @@ BIN = SMESHEngine BIN_SRC = # additionnal information to compil and link file -CPPFLAGS+= $(OCC_INCLUDES) $(MED2_INCLUDES) $(HDF5_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome \ +CPPFLAGS+= $(OCC_INCLUDES) $(HDF5_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome \ -I${GEOM_ROOT_DIR}/include/salome $(BOOST_CPPFLAGS) -CXXFLAGS+= $(OCC_CXXFLAGS) $(MED2_INCLUDES) $(HDF5_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome \ +CXXFLAGS+= $(OCC_CXXFLAGS) $(HDF5_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome \ -I${GEOM_ROOT_DIR}/include/salome LDFLAGS+= -L${KERNEL_ROOT_DIR}/lib/salome -lSalomeContainer -lSalomeNS -lRegistry -lSalomeHDFPersist -lSalomeLifeCycleCORBA -lTOOLSDS -lSalomeGenericObj \ diff --git a/src/SMESH_I/SMESH_Filter_i.cxx b/src/SMESH_I/SMESH_Filter_i.cxx index 052053500..a5c073f29 100644 --- a/src/SMESH_I/SMESH_Filter_i.cxx +++ b/src/SMESH_I/SMESH_Filter_i.cxx @@ -91,7 +91,7 @@ static bool IsContains( SMESHDS_Mesh* theMeshDS, TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE ) { TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum ); - + while( anExp.More() ) { const TopoDS_Shape& aShape = anExp.Current(); @@ -171,6 +171,143 @@ SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS() return myMeshDS; } +/* + Class : LyingOnGeom + Description : Predicate for verifying whether entiy lying or partially lying on + specified geometrical support +*/ + +Controls::LyingOnGeom::LyingOnGeom() +: myMeshDS(NULL), + myType(SMDSAbs_All) +{} + +void Controls::LyingOnGeom::SetMesh( SMDS_Mesh* theMesh ) +{ + myMeshDS = dynamic_cast(theMesh); +} + +void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape ) +{ + myShape = theShape; +} + +bool Controls::LyingOnGeom::IsSatisfy( long theId ) +{ + if ( myMeshDS == 0 || myShape.IsNull() ) + return false; + + if( myType == SMDSAbs_Node ) + { + if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) ) + { + const SMDS_PositionPtr& aPosition = aNode->GetPosition(); + SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition(); + switch( aTypeOfPosition ) + { + case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX ); + case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE ); + case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE ); + case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL ); + } + } + } + else + { + if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) ) + { + if( myType == SMDSAbs_All ) + { + return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) || + Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) || + Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )|| + Contains( myMeshDS,myShape,anElem,TopAbs_SOLID ); + } + else if( myType == anElem->GetType() ) + { + switch( myType ) + { + case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ); + case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE ); + case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )|| + Contains( myMeshDS,myShape,anElem,TopAbs_SOLID ); + } + } + } + } + + return false; +} + +void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType ) +{ + myType = theType; +} + +SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const +{ + return myType; +} + +TopoDS_Shape Controls::LyingOnGeom::GetShape() +{ + return myShape; +} + +SMESHDS_Mesh* Controls::LyingOnGeom::GetMeshDS() +{ + return myMeshDS; +} + +bool Controls::LyingOnGeom::Contains( SMESHDS_Mesh* theMeshDS, + const TopoDS_Shape& theShape, + const SMDS_MeshElement* theElem, + TopAbs_ShapeEnum theFindShapeEnum, + TopAbs_ShapeEnum theAvoidShapeEnum ) +{ + if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum)) + return true; + + if ( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( theShape ) ) + { + SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes(); + while ( aNodeIt->more() ) + { + const SMDS_MeshNode* aNode = static_cast(aNodeIt->next()); + SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator(); + while ( anElemIt->more() ) + { + const SMDS_MeshElement* anElement = static_cast(anElemIt->next()); + if (anElement == theElem) + return true; + } + } + } + + TopExp_Explorer anExp( theShape,TopAbs_VERTEX,theAvoidShapeEnum ); + + while( anExp.More() ) + { + const TopoDS_Shape& aShape = anExp.Current(); + if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){ + SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes(); + while ( aNodeIt->more() ) + { + const SMDS_MeshNode* aNode = static_cast(aNodeIt->next()); + SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator(); + while ( anElemIt->more() ) + { + const SMDS_MeshElement* anElement = static_cast(anElemIt->next()); + if (anElement == theElem) + return true; + } + } + } + anExp.Next(); + } + return false; +} + /* AUXILIARY METHODS @@ -334,6 +471,22 @@ FunctorType AspectRatio_i::GetFunctorType() } +/* + Class : AspectRatio3D + Description : Functor for calculating aspect ratio 3D +*/ +AspectRatio3D_i::AspectRatio3D_i() +{ + myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() ); + myFunctorPtr = myNumericalFunctorPtr; +} + +FunctorType AspectRatio3D_i::GetFunctorType() +{ + return SMESH::FT_AspectRatio3D; +} + + /* Class : Warping_i Description : Functor for calculating warping @@ -411,6 +564,47 @@ FunctorType Length_i::GetFunctorType() return SMESH::FT_Length; } +/* + Class : Length2D_i + Description : Functor for calculating length of edge +*/ +Length2D_i::Length2D_i() +{ + myNumericalFunctorPtr.reset( new Controls::Length2D() ); + myFunctorPtr = myNumericalFunctorPtr; +} + +FunctorType Length2D_i::GetFunctorType() +{ + return SMESH::FT_Length2D; +} + +SMESH::Length2D::Values* Length2D_i::GetValues() +{ + INFOS("Length2D_i::GetValues"); + SMESH::Controls::Length2D::TValues aValues; + myLength2DPtr->GetValues( aValues ); + + long i = 0, iEnd = aValues.size(); + + SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd); + + SMESH::Controls::Length2D::TValues::const_iterator anIter; + for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ ) + { + const SMESH::Controls::Length2D::Value& aVal = *anIter; + SMESH::Length2D::Value &aValue = aResult[ i ]; + + aValue.myLength = aVal.myLength; + aValue.myPnt1 = aVal.myPntId[ 0 ]; + aValue.myPnt2 = aVal.myPntId[ 1 ]; + + } + + INFOS("Length2D_i::GetValuess~"); + return aResult._retn(); +} + /* Class : MultiConnection_i Description : Functor for calculating number of faces conneted to the edge @@ -426,6 +620,46 @@ FunctorType MultiConnection_i::GetFunctorType() return SMESH::FT_MultiConnection; } +/* + Class : MultiConnection2D_i + Description : Functor for calculating number of faces conneted to the edge +*/ +MultiConnection2D_i::MultiConnection2D_i() +{ + myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() ); + myFunctorPtr = myNumericalFunctorPtr; +} + +FunctorType MultiConnection2D_i::GetFunctorType() +{ + return SMESH::FT_MultiConnection2D; +} + +SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues() +{ + INFOS("MultiConnection2D_i::GetValues"); + SMESH::Controls::MultiConnection2D::MValues aValues; + myMulticonnection2DPtr->GetValues( aValues ); + + long i = 0, iEnd = aValues.size(); + + SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd); + + SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter; + for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ ) + { + const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first; + SMESH::MultiConnection2D::Value &aValue = aResult[ i ]; + + aValue.myPnt1 = aVal.myPntId[ 0 ]; + aValue.myPnt2 = aVal.myPntId[ 1 ]; + aValue.myNbConnects = (*anIter).second; + + } + + INFOS("Multiconnection2D_i::GetValuess~"); + return aResult._retn(); +} /* PREDICATES @@ -599,7 +833,57 @@ FunctorType BelongToCylinder_i::GetFunctorType() return FT_BelongToCylinder; } +/* + Class : LyingOnGeom_i + Description : Predicate for selection on geometrical support +*/ +LyingOnGeom_i::LyingOnGeom_i() +{ + myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() ); + myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr; + myShapeName = 0; +} + +LyingOnGeom_i::~LyingOnGeom_i() +{ + delete myShapeName; +} + +void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom ) +{ + if ( theGeom->_is_nil() ) + return; + SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); + GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine(); + TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom ); + myLyingOnGeomPtr->SetGeom( aLocShape ); +} +void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape ) +{ + myLyingOnGeomPtr->SetGeom( theShape ); +} + +void LyingOnGeom_i::SetElementType(ElementType theType){ + myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType)); +} + +FunctorType LyingOnGeom_i::GetFunctorType() +{ + return SMESH::FT_LyingOnGeom; +} + +void LyingOnGeom_i::SetShapeName( const char* theName ) +{ + delete myShapeName; + myShapeName = strdup( theName ); + myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) ); +} + +char* LyingOnGeom_i::GetShapeName() +{ + return CORBA::string_dup( myShapeName ); +} /* Class : FreeBorders_i @@ -974,6 +1258,14 @@ AspectRatio_ptr FilterManager_i::CreateAspectRatio() } +AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D() +{ + SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i(); + SMESH::AspectRatio3D_var anObj = aServant->_this(); + return anObj._retn(); +} + + Warping_ptr FilterManager_i::CreateWarping() { SMESH::Warping_i* aServant = new SMESH::Warping_i(); @@ -1013,6 +1305,12 @@ Length_ptr FilterManager_i::CreateLength() return anObj._retn(); } +Length2D_ptr FilterManager_i::CreateLength2D() +{ + SMESH::Length2D_i* aServant = new SMESH::Length2D_i(); + SMESH::Length2D_var anObj = aServant->_this(); + return anObj._retn(); +} MultiConnection_ptr FilterManager_i::CreateMultiConnection() { @@ -1021,6 +1319,12 @@ MultiConnection_ptr FilterManager_i::CreateMultiConnection() return anObj._retn(); } +MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D() +{ + SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i(); + SMESH::MultiConnection2D_var anObj = aServant->_this(); + return anObj._retn(); +} BelongToGeom_ptr FilterManager_i::CreateBelongToGeom() { @@ -1043,6 +1347,13 @@ BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder() return anObj._retn(); } +LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom() +{ + SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i(); + SMESH::LyingOnGeom_var anObj = aServant->_this(); + return anObj._retn(); +} + FreeBorders_ptr FilterManager_i::CreateFreeBorders() { SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i(); @@ -1283,6 +1594,21 @@ static inline bool getCriteria( Predicate_i* thePred, theCriteria[ i ].TypeOfElement = aPred->GetElementType(); theCriteria[ i ].Tolerance = aPred->GetTolerance(); + return true; + } + case FT_LyingOnGeom: + { + LyingOnGeom_i* aPred = dynamic_cast( thePred ); + + CORBA::ULong i = theCriteria->length(); + theCriteria->length( i + 1 ); + + theCriteria[ i ] = createCriterion(); + + theCriteria[ i ].Type = FT_LyingOnGeom; + theCriteria[ i ].ThresholdStr = aPred->GetShapeName(); + theCriteria[ i ].TypeOfElement = aPred->GetElementType(); + return true; } case FT_RangeOfIds: @@ -1399,12 +1725,21 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria case SMESH::FT_MultiConnection: aFunctor = aFilterMgr->CreateMultiConnection(); break; + case SMESH::FT_MultiConnection2D: + aFunctor = aFilterMgr->CreateMultiConnection2D(); + break; case SMESH::FT_Length: aFunctor = aFilterMgr->CreateLength(); break; + case SMESH::FT_Length2D: + aFunctor = aFilterMgr->CreateLength2D(); + break; case SMESH::FT_AspectRatio: aFunctor = aFilterMgr->CreateAspectRatio(); break; + case SMESH::FT_AspectRatio3D: + aFunctor = aFilterMgr->CreateAspectRatio3D(); + break; case SMESH::FT_Warping: aFunctor = aFilterMgr->CreateWarping(); break; @@ -1450,6 +1785,14 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria aPredicate = tmpPred; } break; + case SMESH::FT_LyingOnGeom: + { + SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom(); + tmpPred->SetElementType( aTypeOfElem ); + tmpPred->SetShapeName( aThresholdStr ); + aPredicate = tmpPred; + } + break; case SMESH::FT_RangeOfIds: { SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds(); @@ -1660,11 +2003,14 @@ static inline LDOMString toString( const long theType ) case FT_BelongToGeom : return "Belong to Geom"; case FT_BelongToPlane : return "Belong to Plane"; case FT_BelongToCylinder: return "Belong to Cylinder"; + case FT_LyingOnGeom : return "Lying on Geom"; case FT_RangeOfIds : return "Range of IDs"; case FT_FreeBorders : return "Free borders"; case FT_FreeEdges : return "Free edges"; case FT_MultiConnection : return "Borders at multi-connections"; + case FT_MultiConnection2D: return "Borders at multi-connections 2D"; case FT_Length : return "Length"; + case FT_Length2D : return "Length2D"; case FT_LessThan : return "Less than"; case FT_MoreThan : return "More than"; case FT_EqualTo : return "Equal to"; @@ -1691,10 +2037,13 @@ static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr ) else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom; else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane; else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder; + else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom; else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders; else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges; else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection; + // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D; else if ( theStr.equals( "Length" ) ) return FT_Length; + // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D; else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds; else if ( theStr.equals( "Less than" ) ) return FT_LessThan; else if ( theStr.equals( "More than" ) ) return FT_MoreThan; @@ -2204,23 +2553,3 @@ string_array* FilterLibrary_i::GetAllNames() return aResArray._retn(); } - - - - - - - - - - - - - - - - - - - - diff --git a/src/SMESH_I/SMESH_Filter_i.hxx b/src/SMESH_I/SMESH_Filter_i.hxx index 2c3efb20e..ce3246602 100644 --- a/src/SMESH_I/SMESH_Filter_i.hxx +++ b/src/SMESH_I/SMESH_Filter_i.hxx @@ -35,7 +35,7 @@ #include #include "SALOME_GenericObj_i.hh" -#include "SMESH_Controls.hxx" +#include "SMESH_ControlsDef.hxx" class SMESHDS_Mesh; @@ -72,6 +72,39 @@ private: SMDSAbs_ElementType myType; }; typedef boost::shared_ptr BelongToGeomPtr; + +/* + Class : LyingOnGeom + Description : Predicate for verifying whether entiy lying or partially lying on + specified geometrical support +*/ +class LyingOnGeom: public virtual Predicate +{ +public: + LyingOnGeom(); + + virtual void SetMesh( SMDS_Mesh* theMesh ); + virtual void SetGeom( const TopoDS_Shape& theShape ); + + virtual bool IsSatisfy( long theElementId ); + + virtual void SetType( SMDSAbs_ElementType theType ); + virtual SMDSAbs_ElementType GetType() const; + + TopoDS_Shape GetShape(); + SMESHDS_Mesh* GetMeshDS(); + + virtual bool Contains( SMESHDS_Mesh* theMeshDS, + const TopoDS_Shape& theShape, + const SMDS_MeshElement* theElem, + TopAbs_ShapeEnum theFindShapeEnum, + TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE ); +private: + TopoDS_Shape myShape; + SMESHDS_Mesh* myMeshDS; + SMDSAbs_ElementType myType; +}; +typedef boost::shared_ptr LyingOnGeomPtr; } /* @@ -141,6 +174,19 @@ public: }; +/* + Class : AspectRatio3D_i + Description : Functor for calculating aspect ratio for 3D +*/ +class AspectRatio3D_i: public virtual POA_SMESH::AspectRatio3D, + public virtual NumericalFunctor_i +{ +public: + AspectRatio3D_i(); + FunctorType GetFunctorType(); +}; + + /* Class : Warping_i Description : Functor for calculating warping @@ -205,6 +251,22 @@ public: FunctorType GetFunctorType(); }; +/* + Class : Length2D_i + Description : Functor for calculating length of edge +*/ +class Length2D_i: public virtual POA_SMESH::Length2D, + public virtual NumericalFunctor_i +{ +public: + Length2D_i(); + SMESH::Length2D::Values* GetValues(); + FunctorType GetFunctorType(); + +protected: + Controls::Length2DPtr myLength2DPtr; +}; + /* Class : MultiConnection_i @@ -218,6 +280,22 @@ public: FunctorType GetFunctorType(); }; +/* + Class : MultiConnection2D_i + Description : Functor for calculating number of faces conneted to the edge +*/ +class MultiConnection2D_i: public virtual POA_SMESH::MultiConnection2D, + public virtual NumericalFunctor_i +{ +public: + MultiConnection2D_i(); + SMESH::MultiConnection2D::Values* GetValues(); + FunctorType GetFunctorType(); + +protected: + Controls::MultiConnection2DPtr myMulticonnection2DPtr; +}; + /* PREDICATES @@ -314,6 +392,30 @@ public: FunctorType GetFunctorType(); }; +/* + Class : LyingOnGeom_i + Description : Predicate for selection on geometrical support(lying or partially lying) +*/ +class LyingOnGeom_i: public virtual POA_SMESH::LyingOnGeom, + public virtual Predicate_i +{ +public: + LyingOnGeom_i(); + virtual ~LyingOnGeom_i(); + + void SetGeom( GEOM::GEOM_Object_ptr theGeom ); + void SetElementType( ElementType theType ); + FunctorType GetFunctorType(); + + void SetGeom( const TopoDS_Shape& theShape ); + + void SetShapeName( const char* theName ); + char* GetShapeName(); + +protected: + Controls::LyingOnGeomPtr myLyingOnGeomPtr; + char* myShapeName; +}; /* Class : FreeBorders_i @@ -583,17 +685,22 @@ public: FilterManager_i(); MinimumAngle_ptr CreateMinimumAngle(); AspectRatio_ptr CreateAspectRatio(); + AspectRatio3D_ptr CreateAspectRatio3D(); Warping_ptr CreateWarping(); Taper_ptr CreateTaper(); Skew_ptr CreateSkew(); Area_ptr CreateArea(); Length_ptr CreateLength(); + Length2D_ptr CreateLength2D(); MultiConnection_ptr CreateMultiConnection(); + MultiConnection2D_ptr CreateMultiConnection2D(); BelongToGeom_ptr CreateBelongToGeom(); BelongToPlane_ptr CreateBelongToPlane(); BelongToCylinder_ptr CreateBelongToCylinder(); + LyingOnGeom_ptr CreateLyingOnGeom(); + FreeBorders_ptr CreateFreeBorders(); FreeEdges_ptr CreateFreeEdges(); diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index c18cd7dc9..f27cc396e 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -533,6 +533,75 @@ void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObjec ExtrusionSweep(anElementsId, theStepVector, theNbOfSteps); } +//======================================================================= +//function : ExtrusionAlongPath +//purpose : +//======================================================================= + +void SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements, + SMESH::SMESH_Mesh_ptr thePathMesh, + GEOM::GEOM_Object_ptr thePathShape, + CORBA::Long theNodeStart, + CORBA::Boolean theHasAngles, + const SMESH::double_array & theAngles, + CORBA::Boolean theHasRefPoint, + const SMESH::PointStruct & theRefPoint) +{ + SMESHDS_Mesh* aMesh = GetMeshDS(); + + if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) + return; + + SMESH_Mesh_i* aMeshImp = dynamic_cast( SMESH_Gen_i::GetServant( thePathMesh ).in() ); + TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape ); + SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape ); + + if ( !aSubMesh ) + return; + + SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart); + if ( !nodeStart ) + return; + + set elements; + for (int i = 0; i < theIDsOfElements.length(); i++) + { + CORBA::Long index = theIDsOfElements[i]; + const SMDS_MeshElement * elem = aMesh->FindElement(index); + if ( elem ) + elements.insert( elem ); + } + + list angles; + for (int i = 0; i < theAngles.length(); i++) + { + angles.push_back( theAngles[i] ); + } + + gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z ); + + ::SMESH_MeshEditor anEditor( _myMesh ); + int res = anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart, theHasAngles, angles, theHasRefPoint, refPnt ); +} + +//======================================================================= +//function : ExtrusionAlongPathObject +//purpose : +//======================================================================= + +void SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject, + SMESH::SMESH_Mesh_ptr thePathMesh, + GEOM::GEOM_Object_ptr thePathShape, + CORBA::Long theNodeStart, + CORBA::Boolean theHasAngles, + const SMESH::double_array & theAngles, + CORBA::Boolean theHasRefPoint, + const SMESH::PointStruct & theRefPoint) +{ + SMESH::long_array_var anElementsId = theObject->GetIDs(); + ExtrusionAlongPath( anElementsId, thePathMesh, thePathShape, theNodeStart, theHasAngles, theAngles, theHasRefPoint, theRefPoint ); +} + //======================================================================= //function : Mirror //purpose : @@ -681,7 +750,8 @@ void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tol { ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes; ::SMESH_MeshEditor anEditor( _myMesh ); - anEditor.FindCoincidentNodes( Tolerance, aListOfListOfNodes ); + set nodes; // no input nodes + anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes ); GroupsOfNodes = new SMESH::array_of_long_array; GroupsOfNodes->length( aListOfListOfNodes.size() ); diff --git a/src/SMESH_I/SMESH_MeshEditor_i.hxx b/src/SMESH_I/SMESH_MeshEditor_i.hxx index 2923617bd..3677d1342 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.hxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.hxx @@ -105,6 +105,24 @@ class SMESH_MeshEditor_i: public POA_SMESH::SMESH_MeshEditor const SMESH::DirStruct & StepVector, CORBA::Long NbOfSteps); + void ExtrusionAlongPath(const SMESH::long_array & IDsOfElements, + SMESH::SMESH_Mesh_ptr PathMesh, + GEOM::GEOM_Object_ptr PathShape, + CORBA::Long NodeStart, + CORBA::Boolean HasAngles, + const SMESH::double_array & Angles, + CORBA::Boolean HasRefPoint, + const SMESH::PointStruct & RefPoint); + + void ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject, + SMESH::SMESH_Mesh_ptr PathMesh, + GEOM::GEOM_Object_ptr PathShape, + CORBA::Long NodeStart, + CORBA::Boolean HasAngles, + const SMESH::double_array & Angles, + CORBA::Boolean HasRefPoint, + const SMESH::PointStruct & RefPoint); + void Mirror(const SMESH::long_array & IDsOfElements, const SMESH::AxisStruct & Axis, SMESH::SMESH_MeshEditor::MirrorType MirrorType, diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 851f61310..8197abb31 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -41,18 +41,18 @@ #include "OpUtil.hxx" #include "TCollection_AsciiString.hxx" -#include -#include -#include #include "SMESHDS_Command.hxx" #include "SMESHDS_CommandType.hxx" #include "SMESH_MeshEditor_i.hxx" #include "SMESH_Gen_i.hxx" #include "DriverMED_R_SMESHDS_Mesh.h" +#include +#include +#include + #include #include -// _CS_gbo_050504 Ajout explicite du sstream pour ostringstream #include #ifdef _DEBUG_ @@ -509,7 +509,7 @@ SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShap catch(SALOME_Exception & S_ex) { THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM); } - return subMesh; + return subMesh._retn(); } //============================================================================= @@ -1049,10 +1049,13 @@ SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor() */ //============================================================================= -void SMESH_Mesh_i::ExportMED(const char *file, CORBA::Boolean auto_groups) throw(SALOME::SALOME_Exception) +void SMESH_Mesh_i::ExportToMED( const char* file, + CORBA::Boolean auto_groups, + SMESH::MED_VERSION theVersion ) + throw(SALOME::SALOME_Exception) { Unexpect aCatch(SALOME_SalomeException); - + char* aMeshName = "Mesh"; SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy(); if ( !aStudy->_is_nil() ) { @@ -1062,10 +1065,10 @@ void SMESH_Mesh_i::ExportMED(const char *file, CORBA::Boolean auto_groups) throw //SCRUTE(file); //SCRUTE(aMeshName); //SCRUTE(aMeshSO->GetID()); - + // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes if ( !aStudy->GetProperties()->IsLocked() ) - { + { SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); SALOMEDS::AttributeExternalFileDef_var aFileName; @@ -1078,10 +1081,17 @@ void SMESH_Mesh_i::ExportMED(const char *file, CORBA::Boolean auto_groups) throw aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr); ASSERT(!aFileType->_is_nil()); aFileType->SetValue("FICHIERMED"); - } + } } } - _impl->ExportMED( file, aMeshName, auto_groups ); + _impl->ExportMED( file, aMeshName, auto_groups, theVersion ); +} + +void SMESH_Mesh_i::ExportMED( const char* file, + CORBA::Boolean auto_groups) + throw(SALOME::SALOME_Exception) +{ + ExportToMED(file,auto_groups,SMESH::MED_V2_1); } void SMESH_Mesh_i::ExportDAT(const char *file) throw(SALOME::SALOME_Exception) @@ -1126,6 +1136,17 @@ CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception) return _impl->NbNodes(); } +//============================================================================= +/*! + * + */ +//============================================================================= +CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + return NbEdges() + NbFaces() + NbVolumes(); +} + //============================================================================= /*! * @@ -1237,3 +1258,98 @@ SMESH::long_array* SMESH_Mesh_i::GetIDs() return aResult._retn(); } + +//============================================================================= +/*! + * + */ +//============================================================================= + +SMESH::long_array* SMESH_Mesh_i::GetElementsId() + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + MESSAGE("SMESH_Mesh_i::GetElementsId"); + SMESH::long_array_var aResult = new SMESH::long_array(); + SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); + + if ( aSMESHDS_Mesh == NULL ) + return aResult._retn(); + + long nbElements = NbElements(); + aResult->length( nbElements ); + SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator(); + for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ ) + aResult[i] = anIt->next()->GetID(); + + return aResult._retn(); +} + + +//============================================================================= +/*! + * + */ +//============================================================================= + +SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType ) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + MESSAGE("SMESH_subMesh_i::GetElementsByType"); + SMESH::long_array_var aResult = new SMESH::long_array(); + SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); + + if ( aSMESHDS_Mesh == NULL ) + return aResult._retn(); + + long nbElements = NbElements(); + + // No sense in returning ids of elements along with ids of nodes: + // when theElemType == SMESH::ALL, return node ids only if + // there are no elements + if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 ) + return GetNodesId(); + + aResult->length( nbElements ); + + int i = 0; + + SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator(); + while ( i < nbElements && anIt->more() ) { + const SMDS_MeshElement* anElem = anIt->next(); + if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType ) + aResult[i++] = anElem->GetID(); + } + + aResult->length( i ); + + return aResult._retn(); +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +SMESH::long_array* SMESH_Mesh_i::GetNodesId() + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + MESSAGE("SMESH_subMesh_i::GetNodesId"); + SMESH::long_array_var aResult = new SMESH::long_array(); + SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); + + if ( aSMESHDS_Mesh == NULL ) + return aResult._retn(); + + long nbNodes = NbNodes(); + aResult->length( nbNodes ); + SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator(); + for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ ) + aResult[i] = anIt->next()->GetID(); + + return aResult._retn(); +} + diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 0b010c474..3035c1ad3 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -150,8 +150,11 @@ public: SMESH::DriverMED_ReadStatus ImportMEDFile( const char* theFileName, const char* theMeshName ) throw (SALOME::SALOME_Exception); + void ExportToMED( const char* file, CORBA::Boolean auto_groups, SMESH::MED_VERSION theVersion ) + throw (SALOME::SALOME_Exception); void ExportMED( const char* file, CORBA::Boolean auto_groups ) throw (SALOME::SALOME_Exception); + void ExportDAT( const char* file ) throw (SALOME::SALOME_Exception); void ExportUNV( const char* file ) @@ -165,6 +168,9 @@ public: CORBA::Long NbNodes() throw (SALOME::SALOME_Exception); + CORBA::Long NbElements() + throw (SALOME::SALOME_Exception); + CORBA::Long NbEdges() throw (SALOME::SALOME_Exception); @@ -195,6 +201,15 @@ public: CORBA::Long NbSubMesh() throw (SALOME::SALOME_Exception); + SMESH::long_array* GetElementsId() + throw (SALOME::SALOME_Exception); + + SMESH::long_array* GetElementsByType( SMESH::ElementType theElemType ) + throw (SALOME::SALOME_Exception); + + SMESH::long_array* GetNodesId() + throw (SALOME::SALOME_Exception); + char* Dump(); // Internal methods not available through CORBA diff --git a/src/SMESH_I/SMESH_Pattern_i.cxx b/src/SMESH_I/SMESH_Pattern_i.cxx index 206d497ba..fa664b4a8 100644 --- a/src/SMESH_I/SMESH_Pattern_i.cxx +++ b/src/SMESH_I/SMESH_Pattern_i.cxx @@ -32,15 +32,20 @@ #include "SMESH_Gen_i.hxx" #include "SMESH_Mesh.hxx" #include "SMESH_Mesh_i.hxx" +#include "SMDS_MeshFace.hxx" +#include "SMDS_MeshVolume.hxx" #include #include #include #include +#include +// ============================================================================= //============================================================================= /*! +// ============================================================================= * SMESH_Gen_i::GetPattern * * Create pattern mapper @@ -64,16 +69,6 @@ SMESH_Pattern_i::SMESH_Pattern_i( SMESH_Gen_i* theGen_i ): { } -//======================================================================= -//function : getShape -//purpose : -//======================================================================= - -TopoDS_Shape SMESH_Pattern_i::getShape( GEOM::GEOM_Object_ptr & theGeomObject ) -{ - return myGen->GetShapeReader()->GetShape( SMESH_Gen_i::GetGeomEngine(), theGeomObject ); -} - //======================================================================= //function : getMesh //purpose : @@ -115,7 +110,7 @@ CORBA::Boolean SMESH_Pattern_i::LoadFromFace(SMESH::SMESH_Mesh_ptr theMesh, if ( !aMesh ) return false; - TopoDS_Face aFace = TopoDS::Face( getShape( theFace )); + TopoDS_Face aFace = TopoDS::Face( myGen->GeomObjectToShape( theFace )); if ( aFace.IsNull() ) return false; @@ -137,7 +132,7 @@ CORBA::Boolean SMESH_Pattern_i::LoadFrom3DBlock(SMESH::SMESH_Mesh_ptr theMesh, if ( !aMesh ) return false; - TopoDS_Shape aShape = getShape( theBlock ); + TopoDS_Shape aShape = myGen->GeomObjectToShape( theBlock ); if ( aShape.IsNull()) return false; @@ -160,8 +155,8 @@ SMESH::point_array* SMESH_Pattern_i::ApplyToFace(GEOM::GEOM_Object_ptr theFace, SMESH::point_array_var points = new SMESH::point_array; list xyzList; - TopoDS_Shape F = getShape( theFace ); - TopoDS_Shape V = getShape( theVertexOnKeyPoint1 ); + TopoDS_Shape F = myGen->GeomObjectToShape( theFace ); + TopoDS_Shape V = myGen->GeomObjectToShape( theVertexOnKeyPoint1 ); if (!F.IsNull() && F.ShapeType() == TopAbs_FACE && !V.IsNull() && V.ShapeType() == TopAbs_VERTEX @@ -192,9 +187,9 @@ SMESH::point_array* SMESH_Pattern_i::ApplyTo3DBlock(GEOM::GEOM_Object_ptr theBlo SMESH::point_array_var points = new SMESH::point_array; list xyzList; - TopExp_Explorer exp( getShape( theBlock ), TopAbs_SHELL ); - TopoDS_Shape V000 = getShape( theVertex000 ); - TopoDS_Shape V001 = getShape( theVertex001 ); + TopExp_Explorer exp( myGen->GeomObjectToShape( theBlock ), TopAbs_SHELL ); + TopoDS_Shape V000 = myGen->GeomObjectToShape( theVertex000 ); + TopoDS_Shape V001 = myGen->GeomObjectToShape( theVertex001 ); if (exp.More() && !V000.IsNull() && V000.ShapeType() == TopAbs_VERTEX && @@ -216,6 +211,86 @@ SMESH::point_array* SMESH_Pattern_i::ApplyTo3DBlock(GEOM::GEOM_Object_ptr theBlo return points._retn(); } +//======================================================================= +//function : ApplyToMeshFaces +//purpose : +//======================================================================= + +SMESH::point_array* + SMESH_Pattern_i::ApplyToMeshFaces(SMESH::SMESH_Mesh_ptr theMesh, + const SMESH::long_array& theFacesIDs, + CORBA::Long theNodeIndexOnKeyPoint1, + CORBA::Boolean theReverse) +{ + SMESH::point_array_var points = new SMESH::point_array; + + ::SMESH_Mesh* aMesh = getMesh( theMesh ); + if ( !aMesh ) + return points._retn(); + + list xyzList; + set fset; + for (int i = 0; i < theFacesIDs.length(); i++) + { + CORBA::Long index = theFacesIDs[i]; + const SMDS_MeshElement * elem = aMesh->GetMeshDS()->FindElement(index); + if ( elem && elem->GetType() == SMDSAbs_Face ) + fset.insert( static_cast( elem )); + } + if (myPattern.Apply( fset, theNodeIndexOnKeyPoint1, theReverse ) && + myPattern.GetMappedPoints( xyzList )) + { + points->length( xyzList.size() ); + list::iterator xyzIt = xyzList.begin(); + for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) { + SMESH::PointStruct & p = points[ i++ ]; + (*xyzIt)->Coord( p.x, p.y, p.z ); + } + } + + return points._retn(); +} + +//======================================================================= +//function : ApplyToHexahedrons +//purpose : +//======================================================================= + +SMESH::point_array* + SMESH_Pattern_i::ApplyToHexahedrons(SMESH::SMESH_Mesh_ptr theMesh, + const SMESH::long_array& theVolumesIDs, + CORBA::Long theNode000Index, + CORBA::Long theNode001Index) +{ + SMESH::point_array_var points = new SMESH::point_array; + + ::SMESH_Mesh* aMesh = getMesh( theMesh ); + if ( !aMesh ) + return points._retn(); + + list xyzList; + set vset; + for (int i = 0; i < theVolumesIDs.length(); i++) + { + CORBA::Long index = theVolumesIDs[i]; + const SMDS_MeshElement * elem = aMesh->GetMeshDS()->FindElement(index); + if ( elem && elem->GetType() == SMDSAbs_Volume && elem->NbNodes() == 8 ) + vset.insert( static_cast( elem )); + } + if (myPattern.Apply( vset, theNode000Index, theNode001Index ) && + myPattern.GetMappedPoints( xyzList )) + { + points->length( xyzList.size() ); + list::iterator xyzIt = xyzList.begin(); + for ( int i = 0; xyzIt != xyzList.end(); xyzIt++ ) { + SMESH::PointStruct & p = points[ i++ ]; + (*xyzIt)->Coord( p.x, p.y, p.z ); + } + } + + return points._retn(); +} + //======================================================================= //function : MakeMesh //purpose : diff --git a/src/SMESH_I/SMESH_Pattern_i.hxx b/src/SMESH_I/SMESH_Pattern_i.hxx index 70520d877..7bcbdff66 100644 --- a/src/SMESH_I/SMESH_Pattern_i.hxx +++ b/src/SMESH_I/SMESH_Pattern_i.hxx @@ -65,6 +65,16 @@ class SMESH_Pattern_i: GEOM::GEOM_Object_ptr theVertex000, GEOM::GEOM_Object_ptr theVertex001); + SMESH::point_array* ApplyToMeshFaces(SMESH::SMESH_Mesh_ptr theMesh, + const SMESH::long_array& theFacesIDs, + CORBA::Long theNodeIndexOnKeyPoint1, + CORBA::Boolean theReverse); + + SMESH::point_array* ApplyToHexahedrons(SMESH::SMESH_Mesh_ptr theMesh, + const SMESH::long_array& theVolumesIDs, + CORBA::Long theNode000Index, + CORBA::Long theNode001Index); + CORBA::Boolean MakeMesh(SMESH::SMESH_Mesh_ptr theMesh); SMESH::SMESH_Pattern::ErrorCode GetErrorCode(); @@ -82,8 +92,6 @@ class SMESH_Pattern_i: private: - TopoDS_Shape getShape( GEOM::GEOM_Object_ptr & theGeomObject ); - ::SMESH_Mesh* getMesh( SMESH::SMESH_Mesh_ptr & theMesh ); ::SMESH_Pattern myPattern; diff --git a/src/SMESH_I/SMESH_test.py b/src/SMESH_I/SMESH_test.py deleted file mode 100644 index 0cc3a94bf..000000000 --- a/src/SMESH_I/SMESH_test.py +++ /dev/null @@ -1,200 +0,0 @@ -# SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses -# -# 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 : SMESH_test.py -# Module : SMESH - -import salome -import geompy -import smeshpy - -import SMESH -import StdMeshers - -# ---- define a box - -box = geompy.MakeBox(0., 0., 0., 100., 200., 300.) -idb = geompy.addToStudy(box, "box") - -# ---- add first face of box in study - -subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["FACE"]) -face = subShapeList[0] -name = geompy.SubShapeName(face, box) -idf = geompy.addToStudyInFather(box, face, name) - -# ---- add shell from box in study - -subShellList = geompy.SubShapeAll(box, geompy.ShapeType["SHELL"]) -shell = subShellList[0] -name = geompy.SubShapeName(shell, box) -ids = geompy.addToStudyInFather(box, shell, name) - -# ---- add first edge of face in study - -edgeList = geompy.SubShapeAll(face, geompy.ShapeType["EDGE"]) -edge = edgeList[0]; -name = geompy.SubShapeName(edge, face) -ide = geompy.addToStudyInFather(face, edge, name) - -# ---- launch SMESH, init a Mesh with the box - -gen = smeshpy.smeshpy() -mesh = gen.CreateMesh(idb) - -print "-------------------------- create Hypothesis" - -print "-------------------------- LocalLength" - -hypo1 = gen.CreateHypothesis("LocalLength", "libStdMeshersEngine.so") -print hypo1.GetName() -print hypo1.GetId() -print hypo1.GetLength() -hypo1.SetLength(100) -print hypo1.GetLength() - -print "-------------------------- bidon" - -hyp3 = gen.CreateHypothesis("bidon", "") - -print "-------------------------- NumberOfSegments" - -hypo3 = gen.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so") -hypo3.SetNumberOfSegments(7) -print hypo3.GetName() -print hypo3.GetNumberOfSegments() -print hypo3.GetId() - -print "-------------------------- MaxElementArea" - -hypo4 = gen.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so") -hypo4.SetMaxElementArea(5000) -print hypo4.GetName() -print hypo4.GetMaxElementArea() -print hypo4.GetId() - -print "-------------------------- Regular_1D" - -algo_1 = gen.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so") -print algo_1.GetName() -print algo_1.GetId() -listHyp = algo_1.GetCompatibleHypothesis() -for hyp in listHyp: - print hyp -print algo_1.GetId() - -print "-------------------------- MEFISTO_2D" - -algo_2 = gen.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so") -print algo_2.GetName() -print algo_2.GetId() -listHyp = algo_2.GetCompatibleHypothesis() -for hyp in listHyp: - print hyp -print algo_2.GetId() - -print "-------------------------- add hypothesis to edge" - -edge = salome.IDToObject(ide) -submesh = mesh.GetSubMesh(edge, "SubMeshEdge") -ret = mesh.AddHypothesis(edge,algo_1) -print ret -ret = mesh.AddHypothesis(edge,hypo1) -print ret - -##print "-------------------------- compute edge" -##ret=gen.Compute(mesh,ide) -##print ret -##log=mesh.GetLog(1); -##for a in log: -## print a - -print "-------------------------- add hypothesis to box" - -box = salome.IDToObject(idb) -submesh = mesh.GetSubMesh(box, "SubMeshBox") -ret = mesh.AddHypothesis(box,algo_1) -print ret -ret = mesh.AddHypothesis(box,hypo1) -print ret -ret = mesh.AddHypothesis(box,algo_2) -print ret -ret = mesh.AddHypothesis(box,hypo4) -print ret - -print "-------------------------- compute" - -ret = gen.Compute(mesh,idf) -print ret -log = mesh.GetLog(1); -for a in log: - print "-------" - ii = 0 - ir = 0 - comType = a.commandType - if comType == 0: - for i in range(a.number): - ind = a.indexes[ii] - ii = ii+1 - r1 = a.coords[ir] - ir = ir+1 - r2 = a.coords[ir] - ir = ir+1 - r3 = a.coords[ir] - ir = ir+1 - print "AddNode %i - %g %g %g" % (ind, r1, r2, r3) - elif comType == 1: - for i in range(a.number): - ind = a.indexes[ii] - ii = ii+1 - i1 = a.indexes[ii] - ii = ii+1 - i2 = a.indexes[ii] - ii = ii+1 - print "AddEdge %i - %i %i" % (ind, i1, i2) - elif comType == 2: - for i in range(a.number): - ind = a.indexes[ii] - ii = ii+1 - i1 = a.indexes[ii] - ii = ii+1 - i2 = a.indexes[ii] - ii = ii+1 - i3 = a.indexes[ii] - ii = ii+1 - print "AddTriangle %i - %i %i %i" % (ind, i1, i2, i3) - -##print "-------------------------- compute box" -##ret=gen.Compute(mesh,idb) -##print ret -##log=mesh.GetLog(1); -##print log - -##shell=salome.IDToObject(ids) -##submesh=mesh.GetElementsOnShape(shell) -##ret=mesh.AddHypothesis(shell,algo_1) -##print ret -##ret=mesh.AddHypothesis(shell,hypo1) -##print ret -##ret=gen.Compute(mesh,ids) -##print ret diff --git a/src/SMESH_SWIG/Makefile.in b/src/SMESH_SWIG/Makefile.in index c6c8c0403..1b40066fa 100644 --- a/src/SMESH_SWIG/Makefile.in +++ b/src/SMESH_SWIG/Makefile.in @@ -55,11 +55,13 @@ EXPORT_PYSCRIPTS = libSMESH_Swig.py \ hole2pyGibi.py \ cyl2geometry.py \ cyl2complementary.py \ + SMESH_test.py\ SMESH_test0.py\ SMESH_test1.py \ SMESH_test2.py \ SMESH_test3.py \ SMESH_test4.py \ + SMESH_test5.py \ SMESH_mechanic.py \ SMESH_mechanic_tetra.py \ SMESH_mechanic_editor.py \ @@ -80,7 +82,8 @@ EXPORT_PYSCRIPTS = libSMESH_Swig.py \ SMESH_demo_hexa2_upd.py \ SMESH_hexaedre.py \ SMESH_Sphere.py \ - SMESH_GroupFromGeom.py + SMESH_GroupFromGeom.py \ + SMESH_GroupLyingOnGeom.py LIB_CLIENT_IDL = SALOMEDS.idl \ SALOME_Exception.idl \ diff --git a/src/SMESH_SWIG/SMESH_GroupLyingOnGeom.py b/src/SMESH_SWIG/SMESH_GroupLyingOnGeom.py new file mode 100644 index 000000000..0df585ed8 --- /dev/null +++ b/src/SMESH_SWIG/SMESH_GroupLyingOnGeom.py @@ -0,0 +1,25 @@ +import SMESH + +def BuildGroupLyingOn(theMesh, theElemType, theName, theShape): + aMeshGen = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH") + + aFilterMgr = aMeshGen.CreateFilterManager() + aFilter = aFilterMgr.CreateFilter() + + aLyingOnGeom = aFilterMgr.CreateLyingOnGeom() + aLyingOnGeom.SetGeom(theShape) + aLyingOnGeom.SetElementType(theElemType) + + aFilter.SetPredicate(aLyingOnGeom) + anIds = aFilter.GetElementsId(theMesh) + + aGroup = theMesh.CreateGroup(theElemType, theName) + aGroup.Add(anIds) + +#Example +from SMESH_test1 import * + +smesh.Compute(mesh, box) +BuildGroupLyingOn(mesh, SMESH.FACE, "Group of faces lying on edge", edge ) + +salome.sg.updateObjBrowser(1); diff --git a/src/SMESH_SWIG/SMESH_test.py b/src/SMESH_SWIG/SMESH_test.py new file mode 100644 index 000000000..d2385f3a9 --- /dev/null +++ b/src/SMESH_SWIG/SMESH_test.py @@ -0,0 +1,200 @@ +# SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses +# +# 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 : SMESH_test.py +# Module : SMESH + +import salome +import geompy +import smeshpy + +import SMESH +import StdMeshers + +# ---- define a box + +box = geompy.MakeBox(0., 0., 0., 100., 200., 300.) +idb = geompy.addToStudy(box, "box") + +# ---- add first face of box in study + +subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["FACE"]) +face = subShapeList[0] +name = geompy.SubShapeName(face, box) +idf = geompy.addToStudyInFather(box, face, name) + +# ---- add shell from box in study + +subShellList = geompy.SubShapeAll(box, geompy.ShapeType["SHELL"]) +shell = subShellList[0] +name = geompy.SubShapeName(shell, box) +ids = geompy.addToStudyInFather(box, shell, name) + +# ---- add first edge of face in study + +edgeList = geompy.SubShapeAll(face, geompy.ShapeType["EDGE"]) +edge = edgeList[0]; +name = geompy.SubShapeName(edge, face) +ide = geompy.addToStudyInFather(face, edge, name) + +# ---- launch SMESH, init a Mesh with the box + +gen = smeshpy.smeshpy() +mesh = gen.CreateMesh(idb) + +print "-------------------------- create Hypothesis" + +print "-------------------------- LocalLength" + +hypo1 = gen.CreateHypothesis("LocalLength", "libStdMeshersEngine.so") +print hypo1.GetName() +print hypo1.GetId() +print hypo1.GetLength() +hypo1.SetLength(100) +print hypo1.GetLength() + +print "-------------------------- bidon" + +hyp3 = gen.CreateHypothesis("bidon", "") + +print "-------------------------- NumberOfSegments" + +hypo3 = gen.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so") +hypo3.SetNumberOfSegments(7) +print hypo3.GetName() +print hypo3.GetNumberOfSegments() +print hypo3.GetId() + +print "-------------------------- MaxElementArea" + +hypo4 = gen.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so") +hypo4.SetMaxElementArea(5000) +print hypo4.GetName() +print hypo4.GetMaxElementArea() +print hypo4.GetId() + +print "-------------------------- Regular_1D" + +algo_1 = gen.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so") +print algo_1.GetName() +print algo_1.GetId() +listHyp = algo_1.GetCompatibleHypothesis() +for hyp in listHyp: + print hyp +print algo_1.GetId() + +print "-------------------------- MEFISTO_2D" + +algo_2 = gen.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so") +print algo_2.GetName() +print algo_2.GetId() +listHyp = algo_2.GetCompatibleHypothesis() +for hyp in listHyp: + print hyp +print algo_2.GetId() + +print "-------------------------- add hypothesis to edge" + +edge = salome.IDToObject(ide) +submesh = mesh.GetSubMesh(edge, "SubMeshEdge") +ret = mesh.AddHypothesis(edge,algo_1) +print ret +ret = mesh.AddHypothesis(edge,hypo1) +print ret + +##print "-------------------------- compute edge" +##ret=gen.Compute(mesh,ide) +##print ret +##log=mesh.GetLog(1); +##for a in log: +## print a + +print "-------------------------- add hypothesis to box" + +box = salome.IDToObject(idb) +submesh = mesh.GetSubMesh(box, "SubMeshBox") +ret = mesh.AddHypothesis(box,algo_1) +print ret +ret = mesh.AddHypothesis(box,hypo1) +print ret +ret = mesh.AddHypothesis(box,algo_2) +print ret +ret = mesh.AddHypothesis(box,hypo4) +print ret + +print "-------------------------- compute face" + +ret = gen.Compute(mesh,idf) +print ret +log = mesh.GetLog(0) # 0 - GetLog without ClearLog after, else if 1 - ClearLog after +for a in log: + print "-------" + ii = 0 + ir = 0 + comType = a.commandType + if comType == 0: + for i in range(a.number): + ind = a.indexes[ii] + ii = ii+1 + r1 = a.coords[ir] + ir = ir+1 + r2 = a.coords[ir] + ir = ir+1 + r3 = a.coords[ir] + ir = ir+1 + print "AddNode %i - %g %g %g" % (ind, r1, r2, r3) + elif comType == 1: + for i in range(a.number): + ind = a.indexes[ii] + ii = ii+1 + i1 = a.indexes[ii] + ii = ii+1 + i2 = a.indexes[ii] + ii = ii+1 + print "AddEdge %i - %i %i" % (ind, i1, i2) + elif comType == 2: + for i in range(a.number): + ind = a.indexes[ii] + ii = ii+1 + i1 = a.indexes[ii] + ii = ii+1 + i2 = a.indexes[ii] + ii = ii+1 + i3 = a.indexes[ii] + ii = ii+1 + print "AddTriangle %i - %i %i %i" % (ind, i1, i2, i3) + +##print "-------------------------- compute box" +##ret=gen.Compute(mesh,idb) +##print ret +##log=mesh.GetLog(1); +##print log + +##shell=salome.IDToObject(ids) +##submesh=mesh.GetElementsOnShape(shell) +##ret=mesh.AddHypothesis(shell,algo_1) +##print ret +##ret=mesh.AddHypothesis(shell,hypo1) +##print ret +##ret=gen.Compute(mesh,ids) +##print ret diff --git a/src/SMESH_SWIG/SMESH_test5.py b/src/SMESH_SWIG/SMESH_test5.py index 7259b6e35..8a9e148dd 100644 --- a/src/SMESH_SWIG/SMESH_test5.py +++ b/src/SMESH_SWIG/SMESH_test5.py @@ -50,7 +50,8 @@ def ConvertMED2UNV(thePath,theFile) : SetSObjName(anSObj,aFileName) print anSObj.GetName() - aFileName = thePath + theFile + "." + str(iMesh) + ".unv" + aOutPath = '/tmp/' + aFileName = aOutPath + theFile + "." + str(iMesh) + ".unv" aMesh.ExportUNV(aFileName) aMesh = smesh.CreateMeshesFromUNV(aFileName) anSObj = salome.ObjectToSObject(aMesh) diff --git a/src/SMESH_SWIG/cyl2complementary.py b/src/SMESH_SWIG/cyl2complementary.py index c5a7f9afc..70a41a971 100644 --- a/src/SMESH_SWIG/cyl2complementary.py +++ b/src/SMESH_SWIG/cyl2complementary.py @@ -79,7 +79,9 @@ d_element[10] = MakeCut(d_element[10], c_cyl) # Compound # -------- -piece = MakeCompound(d_element) +comp_all = MakeCompound(d_element) +piece = BlocksOp.RemoveExtraEdges(comp_all) +#piece = MakeCompound(d_element) # Add piece in study # ------------------ diff --git a/src/SMESH_SWIG/cyl2geometry.py b/src/SMESH_SWIG/cyl2geometry.py index 9e27f79ec..5509d6a48 100644 --- a/src/SMESH_SWIG/cyl2geometry.py +++ b/src/SMESH_SWIG/cyl2geometry.py @@ -149,7 +149,8 @@ cpd = cpd + r_element # Compound # -------- -piece = MakeCompound(cpd) +comp_all = MakeCompound(cpd) +piece = BlocksOp.RemoveExtraEdges(comp_all) # Ajouter la piece dans l'etude # ----------------------------- diff --git a/src/SMESH_SWIG/meshpy.py b/src/SMESH_SWIG/meshpy.py index effc62d1d..528e4fe21 100644 --- a/src/SMESH_SWIG/meshpy.py +++ b/src/SMESH_SWIG/meshpy.py @@ -5,13 +5,16 @@ # ------ import geompy - import salome import StdMeshers - import SMESH +""" + \namespace meshpy + \brief Module meshpy +""" + # Variables # --------- @@ -20,24 +23,29 @@ smesh.SetCurrentStudy(salome.myStudy) smeshgui = salome.ImportComponentGUI("SMESH") smeshgui.Init(salome.myStudyId) -# Hexahedrical meshing -# -# Examples: cube2pyGibi.py, lines 270-295 -# cube2partition.py, lines 72-83 -# -------------------- - class MeshHexaImpl: +""" + Class MeshHexaImpl for Hexahedrical meshing + + Examples: cube2pyGibi.py, lines 270-295 + cube2partition.py, lines 72-83 +""" piece = 0 name = 0 mesh = 0 cpt = 0 - # Sets algorithm and hypothesis for 1D discretization of the : - # - algorithm "Regular_1D" - # - hypothesis "NumberOfSegments" with number of segments - # -------------------- - - def Mesh1D(self, shape, n): + def Mesh1D(self, shape, n, propagate=0): + """ + Define Wires discretization. + Sets algorithm and hypothesis for 1D discretization of \a shape: + - algorithm "Regular_1D" + - hypothesis "NumberOfSegments" with number of segments \a n + \param shape Main shape or sub-shape to define wire discretization of + \param n Number of segments to split eash wire of the \a shape on + \param propagate Boolean flag. If propagate = 1, + "Propagation" hypothesis will be applied also to the \a shape + """ hyp1D=smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so") smeshgui.SetName(salome.ObjectToID(hyp1D), self.name+"/WireDiscretisation/"+str(self.cpt)) self.mesh.AddHypothesis(shape, hyp1D) @@ -47,23 +55,31 @@ class MeshHexaImpl: smeshgui.SetName(salome.ObjectToID(hyp), self.name+"/Segments_"+str(n)+"/"+str(self.cpt)) self.mesh.AddHypothesis(shape, hyp) - self.cpt=self.cpt+1 + if propagate: + hypPro=smesh.CreateHypothesis("Propagation", "libStdMeshersEngine.so") + smeshgui.SetName(salome.ObjectToID(hypPro), self.name+"/Propagation/"+str(self.cpt)) + self.mesh.AddHypothesis(shape, hypPro) - # Constructor - # - # Creates mesh on the shape , - # sets GUI name of this mesh to . - # Sets the following global algorithms and hypotheses: - # - for 1D discretization: - # - algorithm "Regular_1D" - # - hypothesis "NumberOfSegments" with number of segments , - # - for 2D discretization: - # - algorithm "Quadrangle_2D" - # - for 3D discretization: - # - algorithm "Hexa_3D" - # -------------------- + self.cpt=self.cpt+1 def __init__(self, piece, n, name): + """ + Constructor + + Creates mesh on the shape \a piece, + sets GUI name of this mesh to \a name. \n + Sets the following global algorithms and hypotheses: + - for 1D discretization: + - algorithm "Regular_1D" + - hypothesis "NumberOfSegments" with number of segments \a n + - for 2D discretization: + - algorithm "Quadrangle_2D" + - for 3D discretization: + - algorithm "Hexa_3D" + \param piece Shape to be meshed + \param n Global number of segments for wires discretization + \param name Name for mesh to be created + """ self.piece = piece self.name = name @@ -80,30 +96,50 @@ class MeshHexaImpl: smeshgui.SetName(salome.ObjectToID(hyp3D), name+"/ijk") self.mesh.AddHypothesis(piece, hyp3D) - # Creates sub-mesh of the mesh, created by constructor. - # This sub-mesh will be created on edge . - # Set algorithm and hypothesis for 1D discretization of the : - # - algorithm "Regular_1D" - # - hypothesis "NumberOfSegments" with number of segments - # Note: the will be automatically published in study under the shape, given in constructor. - # -------------------- - def local(self, edge, n): + """ + Creates sub-mesh of the mesh, created by constructor. + This sub-mesh will be created on edge \a edge. + Set algorithm and hypothesis for 1D discretization of the \a edge: + - algorithm "Regular_1D" + - hypothesis "NumberOfSegments" with number of segments \a n + \param edge Sub-edge of the main shape + \param n Number of segments to split the \a edge on + \note: \a edge will be automatically published in study under the shape, given in constructor. + """ geompy.addToStudyInFather(self.piece, edge, geompy.SubShapeName(edge, self.piece)) submesh = self.mesh.GetSubMesh(edge, self.name+"/SubMeshEdge/"+str(self.cpt)) self.Mesh1D(edge, n) - # Computes mesh, created by constructor. - # -------------------- + def Propagate(self, edge, n): + """ + Creates sub-mesh of the mesh, created by constructor. + This sub-mesh will be created on edge \a edge and propagate the hypothesis on all correspondant edges. + Set algorithm and hypothesis for 1D discretization of the \a edge and all other propagate edges: + - algorithm "Regular_1D" + - hypothesis "NumberOfSegments" with number of segments \a n + - hypothesis "Propagation" + \param edge Sub-edge of the main shape + \param n Number of segments to split the \a edge and all other propagate edges on + \note: \a edge will be automatically published in study under the shape, given in constructor. + """ + geompy.addToStudyInFather(self.piece, edge, geompy.SubShapeName(edge, self.piece)) + submesh = self.mesh.GetSubMesh(edge, self.name+"/SubMeshEdge/"+str(self.cpt)) + self.Mesh1D(edge, n, 1) def Compute(self): + """ + Computes mesh, created by constructor. + """ smesh.Compute(self.mesh, self.piece) salome.sg.updateObjBrowser(1) - # Creates mesh group based on a geometric group - # -------------------- - def Group(self, grp, name=""): + """ + Creates mesh group based on a geometric group + \param grp Geometric group + \param name Name for mesh group to be created + """ if name == "": name = grp.GetName() tgeo = geompy.GroupOp.GetType(grp) @@ -117,10 +153,12 @@ class MeshHexaImpl: type = SMESH.VOLUME return self.mesh.CreateGroupFromGEOM(type, name, grp) - # Export mesh in a MED file - # -------------------- - def ExportMED(self, filename, groups=1): + """ + Export mesh in a MED file + \param filename Name for MED file to be created + \param groups Boolean flag. If groups = 1, mesh groups will be also stored in file + """ self.mesh.ExportMED(filename, groups) MeshHexa = MeshHexaImpl diff --git a/src/StdMeshers/StdMeshers_Regular_1D.cxx b/src/StdMeshers/StdMeshers_Regular_1D.cxx index d7d2e844e..86831c6b5 100644 --- a/src/StdMeshers/StdMeshers_Regular_1D.cxx +++ b/src/StdMeshers/StdMeshers_Regular_1D.cxx @@ -218,7 +218,7 @@ bool StdMeshers_Regular_1D::computeInternalParameters(const TopoDS_Edge& theEdge double factor = length / (1 - pow( alpha,_value[ NB_SEGMENTS_IND ])); - int i, NbPoints = (int) _value[ NB_SEGMENTS_IND ]; + int i, NbPoints = 1 + (int) _value[ NB_SEGMENTS_IND ]; for ( i = 2; i < NbPoints; i++ ) { double param = factor * (1 - pow(alpha, i - 1)); diff --git a/src/StdMeshersGUI/Makefile.in b/src/StdMeshersGUI/Makefile.in index 86eb49764..fd44b0e5d 100644 --- a/src/StdMeshersGUI/Makefile.in +++ b/src/StdMeshersGUI/Makefile.in @@ -66,7 +66,7 @@ LIB_SERVER_IDL = # additionnal information to compil and link file CPPFLAGS += $(QT_INCLUDES) $(VTK_INCLUDES) $(OGL_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES) \ - $(MED2_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome -I${GEOM_ROOT_DIR}/include/salome \ + -I${KERNEL_ROOT_DIR}/include/salome -I${GEOM_ROOT_DIR}/include/salome \ $(BOOST_CPPFLAGS) CXXFLAGS += -I${KERNEL_ROOT_DIR}/include/salome -I${GEOM_ROOT_DIR}/include/salome #$(OCC_CXXFLAGS)