0022761: [EDF] Improvement of Explode dialog box

This commit is contained in:
ova 2014-10-14 12:22:46 +04:00 committed by vsr
parent 72073a0f52
commit 110596005f
8 changed files with 309 additions and 309 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -2,49 +2,75 @@
\page create_explode_page Explode \page create_explode_page Explode
\n To \b Explode an object into sub-shapes, in the <b>Main Menu</b> To \b Explode an object into sub-shapes, in the <b>Main Menu</b>
select <b>New Entity > Explode</b>. select <b>New Entity > Explode</b>. This operation opens the
<b>Sub Shapes Selection</b> dialog box.
\n To create a list of sub-shapes (vertices, edges, wires etc.) of the \image html neo-obj1.png
To create a list of sub-shapes (vertices, edges, wires etc.) of the
given shape using the \b Explode operation, you need to define the <b>Main given shape using the \b Explode operation, you need to define the <b>Main
Object</b>, which will be exploded and the <b>Type of Sub-shapes</b> you wish to Object</b>, which will be exploded and the <b>Type of Sub-shapes</b> you wish to
obtain from it. obtain from it.
\n The \b Result of the operation will be a List of \b GEOM_Objects
The \b Result of the operation will be a List of \b GEOM_Objects
(vertexes, edges, wires, faces, shells or solids). (vertexes, edges, wires, faces, shells or solids).
\n Using <b>TUI Commands</b> you can perform this operation in a Available choices in the <b>Sub Shapes Type</b> combo box depend on the type
of selected <b>Main Object</b>:
- \b Compound: to extract compounds;
- \b Compsolid: to extract compsolids;
- \b Solid: to extract solids;
- \b Shell: to extract shells;
- \b Face: to extract faces;
- \b Wire: to extract wires;
- \b Edge: to extract edges;
- \b Vertex: to extract vertices;
- \b Shape: to extract top-level contents of the compound shape;
- \b Flat: to extract "flat" contents of the compound shape.
Note: "flat" contents means top-level simple-type sub-shapes extracted from
the compound object recursively (i.e. there is no compounds in the result).
For example, if a compound C1 contains a solid S1 and another compound C2 that
contains solids S2 and S3 (see picture below):
- Explode operation with \b Shape type given as parameter will return S1 and C2;
- Explode operation with \b Flat type given as parameter will return S1, S2 and S3.
\image html flat_contents.png
Switching on <b>Select Sub-shapes</b> check box allows manual selection of sub-shapes
to be extracted from the main object. In this mode the user can select sub-shapes
directly in 3D viewer.
Using <b>TUI Commands</b> you can perform this operation in a
variety of ways: variety of ways:
<ul> - <em>geompy.ExtractShapes(Shape, Type, isSorted)</em> explodes a
<li><em>geompy.ExtractShapes(Shape, Type, isSorted)</em> explodes a Shape into sub-shapes of a given Type and returns a List of sub-shapes.
Shape into sub-shapes of a given Type and returns a List of sub-shapes. This method does not return the Shape itself if it matches the
This method does not return the Shape itself if it matches the Type.
Type.</li> - <em>geompy.SubShapeAll(Shape, Type)</em> explodes a Shape on
<li><em>geompy.SubShapeAll(Shape, Type)</em> explodes a Shape on sub-shapes of a given Type and returns a List of sub-shapes.
sub-shapes of a given Type and returns a List of sub-shapes.</li> - <em>geompy.SubShapeAllIDs(Shape, Type)</em> explodes a Shape on
<li><em>geompy.SubShapeAllIDs(Shape, Type)</em> explodes a Shape on sub-shapes of a given Type and returns a List of IDs of
sub-shapes of a given Type and returns a List of IDs of sub-shapes.
sub-shapes.</li> - <em>geompy.SubShapeAllSortedCentres(Shape, Type)</em> explodes a
<li><em>geompy.SubShapeAllSortedCentres(Shape, Type)</em> explodes a shape on sub-shapes of a given type and sorts them taking into account
shape on sub-shapes of a given type and sorts them taking into account their gravity centers, to provide stable order of sub-shapes.
their gravity centers, to provide stable order of sub-shapes. It returns a list of sub-shapes.
It returns a list of sub-shapes.</li> - <em>geompy.SubShapeAllSortedCentresIDs(Shape, Type)</em> explodes
<li><em>geompy.SubShapeAllSortedCentresIDs(Shape, Type)</em> explodes a shape on sub-shapes of a given type and sorts them taking into
a shape on sub-shapes of a given type and sorts them taking into account their gravity centers, to provide stable order of sub-shapes.
account their gravity centers, to provide stable order of sub-shapes. It returns a List of IDs of sub-shapes.
It returns a List of IDs of sub-shapes.</li> - <em>geompy.SubShape(Shape, Type, ListOfInd)</em> allows to obtain
<li><em>geompy.SubShape(Shape, Type, ListOfInd)</em> allows to obtain a compound of sub-shapes of the Shape, selected by they indices in a
a compound of sub-shapes of the Shape, selected by they indices in a list of all sub-shapes of the given Type. Each index is in the range
list of all sub-shapes of the given Type. Each index is in the range [1, Nb_Sub-Shapes_Of_Given_Type].
[1, Nb_Sub-Shapes_Of_Given_Type].</li> - <em>geompy.SubShapeSortedCentres(Shape, Type, ListOfInd)</em>
<li><em>geompy.SubShapeSortedCentres(Shape, Type, ListOfInd)</em> allows to obtain a compound of sub-shapes of the Shape, selected by
allows to obtain a compound of sub-shapes of the Shape, selected by they indices in sorted list of all sub-shapes of the given Type. Each
they indices in sorted list of all sub-shapes of the given Type. Each index is in the range [1, Nb_Sub-Shapes_Of_Given_Type]
index is in the range [1, Nb_Sub-Shapes_Of_Given_Type]</li>
</ul>
\n <b>Arguments: </b>1 SHAPE + 1 type of SubShape. <b>Arguments: </b>1 SHAPE + 1 type of SubShape.
\image html neo-obj1.png
<b>Example:</b> <b>Example:</b>

View File

@ -39,7 +39,7 @@ module GEOM
*/ */
enum shape_type enum shape_type
{ {
/*! */ /*! A collection of arbitrary shapes */
COMPOUND, COMPOUND,
/*! A collection of solids */ /*! A collection of solids */
COMPSOLID, COMPSOLID,
@ -47,16 +47,19 @@ module GEOM
SOLID, SOLID,
/*! A collection of faces connected by some edges of their wire boundaries */ /*! A collection of faces connected by some edges of their wire boundaries */
SHELL, SHELL,
/*! Part of a plane (in 2D geometry) or a surface (in 3D geometry) bounded by a close wire */ /*! Part of a plane (in 2D geometry) or a surface (in 3D geometry) bounded by a closed wire */
FACE, FACE,
/*! A sequence of edges connected by their vertices */ /*! A sequence of edges connected by their vertices */
WIRE, WIRE,
/*! Edge, a shape corresponding to a curve, and bound by a vertex at each extremity */ /*! Edge, a shape corresponding to a curve, and bound by a vertex at each extremity */
EDGE, EDGE,
/*! A zero-dimensional shape corresponding to a point in geometry */ /*! A zero-dimensional shape corresponding to a point in geometry */
VERTEX, VERTEX,
/*! */ /*! Arbitrary shape in a Compound (used for processing of Compounds in some operations) */
SHAPE }; SHAPE,
/*! Flat (top-level) contents of a Compound (used for processing of Compounds in some operations) */
FLAT
};
/*! /*!
* \brief Marker type * \brief Marker type

View File

@ -55,6 +55,62 @@
#include <GEOMImpl_Types.hxx> #include <GEOMImpl_Types.hxx>
namespace
{
const char* const ShapeTypes [] = {
"Compound",
"Compsolid",
"Solid",
"Shell",
"Face",
"Wire",
"Edge",
"Vertex",
"Shape",
"Flat"
};
unsigned int NumberOfSubShapes(const TopoDS_Shape& S, const int shapeType, TopTools_MapOfShape& M)
{
unsigned int index = 0;
if (!S.IsNull()) {
if (S.ShapeType() == TopAbs_COMPOUND &&
(shapeType == TopAbs_SHAPE || shapeType == TopAbs_FLAT || shapeType == TopAbs_COMPOUND)) {
TopoDS_Iterator It(S, Standard_True, Standard_True);
for (; It.More(); It.Next()) {
TopoDS_Shape SS = It.Value();
if (M.Add(SS)) {
if (shapeType == TopAbs_FLAT) {
if (SS.ShapeType() != TopAbs_COMPOUND)
index++;
else
index += NumberOfSubShapes(SS, shapeType, M);
}
else if (shapeType == TopAbs_SHAPE || shapeType == SS.ShapeType()) {
index++;
}
}
}
}
else {
TopExp_Explorer Exp (S, TopAbs_ShapeEnum(shapeType));
for (; Exp.More(); Exp.Next()) {
if (M.Add(Exp.Current())) {
index++;
}
}
}
}
return index;
}
unsigned int NumberOfSubShapes(const TopoDS_Shape& S, const int shapeType)
{
TopTools_MapOfShape M;
return NumberOfSubShapes(S, shapeType, M);
}
}
//================================================================================= //=================================================================================
// class : EntityGUI_SubShapeDlg // class : EntityGUI_SubShapeDlg
// purpose : Constructs a EntityGUI_SubShapeDlg which is a child of 'parent', with the // purpose : Constructs a EntityGUI_SubShapeDlg which is a child of 'parent', with the
@ -66,7 +122,6 @@ EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg(GeometryGUI* theGeometryGUI, QWidge
bool modal, Qt::WindowFlags fl) bool modal, Qt::WindowFlags fl)
: GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl), : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
myDmMode( -1 ), myDmMode( -1 ),
myWithShape(true),
myIsHiddenMain(false) myIsHiddenMain(false)
{ {
QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUBSHAPE"))); QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUBSHAPE")));
@ -133,18 +188,9 @@ void EntityGUI_SubShapeDlg::Init()
myEditCurrentArgument = GroupPoints->LineEdit1; myEditCurrentArgument = GroupPoints->LineEdit1;
myObject = GEOM::GEOM_Object::_nil(); myObject = GEOM::GEOM_Object::_nil();
myWithShape = true;
/* type for sub-shape selection */ /* type for sub-shape selection */
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compound"); for ( int i = 0; i <= (int)GEOM::FLAT; i++ )
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compsolid"); GroupPoints->ComboBox1->addItem(ShapeTypes[i], i);
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Solid");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shell");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Face");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Wire");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Edge");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Vertex");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
!= OCCViewer_Viewer::Type()) != OCCViewer_Viewer::Type())
@ -172,6 +218,7 @@ void EntityGUI_SubShapeDlg::Init()
updateButtonState(); updateButtonState();
resize(100,100); resize(100,100);
SelectionIntoArgument(); SelectionIntoArgument();
SubShapeToggled();
} }
//================================================================================= //=================================================================================
@ -282,6 +329,8 @@ void EntityGUI_SubShapeDlg::SelectionIntoArgument()
if (!isAllSubShapes()) if (!isAllSubShapes())
return; return;
int currentType = GroupPoints->ComboBox1->itemData( GroupPoints->ComboBox1->currentIndex() ).toInt();
ResetStateOfDialog(); ResetStateOfDialog();
QString aString = ""; /* name of selection */ QString aString = ""; /* name of selection */
@ -291,87 +340,47 @@ void EntityGUI_SubShapeDlg::SelectionIntoArgument()
aSelMgr->selectedObjects(aSelList); aSelMgr->selectedObjects(aSelList);
int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true); int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
if (nbSel != 1) if (nbSel == 1) {
return; Handle(SALOME_InteractiveObject) IO = aSelList.First();
if (!IO->hasEntry()) {
Handle(SALOME_InteractiveObject) IO = aSelList.First(); SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
if (!IO->hasEntry()) {
SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
updateButtonState();
return;
}
if (myIsHiddenMain) {
GEOM_Displayer* aDisplayer = getDisplayer();
aDisplayer->Display(myObject);
myIsHiddenMain = false;
}
TopoDS_Shape S = GEOMBase::GetTopoFromSelection(aSelList);
if (S.IsNull() || S.ShapeType() == TopAbs_VERTEX) {
myObject = GEOM::GEOM_Object::_nil();
updateButtonState();
return;
}
myObject = GEOMBase::ConvertIOinGEOMObject(IO);
if (myObject->_is_nil()) {
updateButtonState();
return;
}
myShape = S;
GroupPoints->LineEdit1->setText(aString);
int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
int count = GroupPoints->ComboBox1->count();
if (myWithShape)
count = count - 1;
int i = 0;
// Solving PAL5590
if (myShape.ShapeType() == TopAbs_COMPOUND) {
unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND);
if (nb > 0)
i++;
}
while (i <= myShape.ShapeType()) {
GroupPoints->ComboBox1->removeItem(0);
i++;
}
if (myShape.ShapeType() == TopAbs_COMPOUND) {
if (myWithShape == false) {
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
myWithShape = true;
} }
} else {
else { TopoDS_Shape S = GEOMBase::GetTopoFromSelection(aSelList);
if (myWithShape == true) { if (S.IsNull() || S.ShapeType() == TopAbs_VERTEX) {
GroupPoints->ComboBox1->removeItem(GroupPoints->ComboBox1->count() - 1); myObject = GEOM::GEOM_Object::_nil();
myWithShape = false;
}
}
int count1 = GroupPoints->ComboBox1->count();
if (myWithShape)
count1 = count1 - 1;
if (SelectedShapeType > myShape.ShapeType()) {
if (SelectedShapeType == 8) {
if (myShape.ShapeType() != TopAbs_COMPOUND) {
GroupPoints->ComboBox1->setCurrentIndex(0);
ComboTextChanged();
} }
} else {
else myObject = GEOMBase::ConvertIOinGEOMObject(IO);
GroupPoints->ComboBox1->setCurrentIndex(count1 - count + SelectedShapeType); if (!CORBA::is_nil(myObject)) {
} myShape = S;
else { GroupPoints->LineEdit1->setText(aString);
GroupPoints->ComboBox1->setCurrentIndex(0); int i = 0;
ComboTextChanged(); // Solving PAL5590
} if (myShape.ShapeType() == TopAbs_COMPOUND) {
unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND);
if (nb > 0)
i++;
}
while (i <= myShape.ShapeType()) {
GroupPoints->ComboBox1->removeItem(0);
i++;
}
// remove Shape and Flat types for non-compound shapes
if (myShape.ShapeType() != TopAbs_COMPOUND) {
int idx = GroupPoints->ComboBox1->findData( (int)GEOM::SHAPE );
if ( idx != -1 ) GroupPoints->ComboBox1->removeItem( idx );
idx = GroupPoints->ComboBox1->findData( (int)GEOM::FLAT );
if ( idx != -1 ) GroupPoints->ComboBox1->removeItem( idx );
} // if (myShape.ShapeType() != TopAbs_COMPOUND)
} // if (!CORBA::is_nil(myObject))
} // if (S.IsNull() || S.ShapeType() == TopAbs_VERTEX)
} // if (!IO->hasEntry()) ... else
} // if (nbSel == 1)
int idx = GroupPoints->ComboBox1->findData( currentType );
if ( idx != -1 )
GroupPoints->ComboBox1->setCurrentIndex( idx );
updateButtonState(); updateButtonState();
} }
@ -420,29 +429,10 @@ void EntityGUI_SubShapeDlg::ResetStateOfDialog()
myShape.Nullify(); myShape.Nullify();
myEditCurrentArgument->setText(""); myEditCurrentArgument->setText("");
int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
int count = GroupPoints->ComboBox1->count();
if (myWithShape)
count = count - 1;
/* type for sub-shape selection */ /* type for sub-shape selection */
GroupPoints->ComboBox1->clear(); GroupPoints->ComboBox1->clear();
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compound"); for ( int i = 0; i <= (int)GEOM::FLAT; i++ )
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compsolid"); GroupPoints->ComboBox1->addItem(ShapeTypes[i], i);
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Solid");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shell");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Face");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Wire");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Edge");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Vertex");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
myWithShape = true;
GroupPoints->ComboBox1->setCurrentIndex(8 - count + SelectedShapeType);
// to avoid recursion: SelectionIntoArgument->ResetStateOfDialog->ComboTextChanged->SubShapeToggled->activateSelection->(currentSelectionChanged)->SelectionIntoArgument
//ComboTextChanged();
updateButtonState(); updateButtonState();
} }
@ -472,59 +462,23 @@ void EntityGUI_SubShapeDlg::ComboTextChanged()
SubShapeToggled(); SubShapeToggled();
} }
//=================================================================================
// function : NumberOfSubShapes()
// purpose :
//=================================================================================
unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes(const TopoDS_Shape& S,
const int shapeType) const
{
if (S.IsNull())
return 0;
unsigned int index = 0;
TopTools_MapOfShape M;
if (S.ShapeType() == TopAbs_COMPOUND &&
(TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
TopAbs_ShapeEnum(shapeType) == TopAbs_COMPSOLID ||
TopAbs_ShapeEnum(shapeType) == TopAbs_COMPOUND)) {
TopoDS_Iterator It(S, Standard_True, Standard_True);
for (; It.More(); It.Next()) {
if (M.Add(It.Value())) {
if (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
TopAbs_ShapeEnum(shapeType) == It.Value().ShapeType()) {
index++;
}
}
}
}
else {
TopExp_Explorer Exp (S, TopAbs_ShapeEnum(shapeType));
for (; Exp.More(); Exp.Next()) {
if (M.Add(Exp.Current())) {
index++;
}
}
}
M.Clear();
return index;
}
//================================================================================= //=================================================================================
// function : updateButtonState // function : updateButtonState
// purpose : // purpose :
//================================================================================= //=================================================================================
void EntityGUI_SubShapeDlg::updateButtonState() void EntityGUI_SubShapeDlg::updateButtonState()
{ {
if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() != OCCViewer_Viewer::Type() || bool viewOk = SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() == OCCViewer_Viewer::Type();
myObject->_is_nil() || shapeType() == TopAbs_SHAPE || shapeType() == TopAbs_COMPOUND) { bool shapeTypeOk = shapeType() != TopAbs_SHAPE && shapeType() != TopAbs_FLAT && shapeType() != TopAbs_COMPOUND;
GroupPoints->CheckButton1->setChecked(false); bool objectOK = !CORBA::is_nil( myObject );
GroupPoints->CheckButton1->setEnabled(false);
if ( viewOk && objectOK && shapeTypeOk ) {
GroupPoints->CheckButton1->setEnabled( true );
}
else {
GroupPoints->CheckButton1->setChecked( false );
GroupPoints->CheckButton1->setEnabled( false );
} }
else
GroupPoints->CheckButton1->setEnabled(true);
} }
//================================================================================= //=================================================================================
@ -533,7 +487,7 @@ void EntityGUI_SubShapeDlg::updateButtonState()
//================================================================================= //=================================================================================
bool EntityGUI_SubShapeDlg::isAllSubShapes() const bool EntityGUI_SubShapeDlg::isAllSubShapes() const
{ {
return !GroupPoints->CheckButton1->isChecked() || !GroupPoints->CheckButton1->isEnabled(); return !GroupPoints->CheckButton1->isEnabled() || !GroupPoints->CheckButton1->isChecked();
} }
//================================================================================= //=================================================================================
@ -542,19 +496,7 @@ bool EntityGUI_SubShapeDlg::isAllSubShapes() const
//================================================================================= //=================================================================================
int EntityGUI_SubShapeDlg::shapeType() const int EntityGUI_SubShapeDlg::shapeType() const
{ {
int type = GroupPoints->ComboBox1->currentIndex(); return GroupPoints->ComboBox1->itemData(GroupPoints->ComboBox1->currentIndex()).toInt();
if (myObject->_is_nil())
return type;
// Solving PAL5590
type += myShape.ShapeType() + 1;
if (myShape.ShapeType() == TopAbs_COMPOUND &&
NumberOfSubShapes(myShape, TopAbs_COMPOUND) > 0) {
type--;
}
return type;
} }
//================================================================================= //=================================================================================

View File

@ -73,9 +73,6 @@ private:
void ResetStateOfDialog(); void ResetStateOfDialog();
unsigned int NumberOfSubShapes (const TopoDS_Shape&,
const int) const;
void activateSelection(); void activateSelection();
int getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex); int getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex);
void updateButtonState(); void updateButtonState();
@ -87,8 +84,6 @@ private:
GEOM::GEOM_Object_var myObject; GEOM::GEOM_Object_var myObject;
int myDmMode; int myDmMode;
bool myWithShape;
bool myIsHiddenMain; bool myIsHiddenMain;
DlgRef_1Sel1List1Check3Btn* GroupPoints; DlgRef_1Sel1List1Check3Btn* GroupPoints;

View File

@ -135,6 +135,63 @@
#include <Standard_Failure.hxx> #include <Standard_Failure.hxx>
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
namespace {
//================================================================================
/*!
* \brief Return normal to face at extrema point
*/
//================================================================================
gp_Vec GetNormal (const TopoDS_Face& face, const BRepExtrema_DistShapeShape& extrema)
{
gp_Vec defaultNorm(1,0,0); // to have same normals on different faces
try {
// get UV at extrema point
Standard_Real u,v, f,l;
switch ( extrema.SupportTypeShape2(1) ) {
case BRepExtrema_IsInFace: {
extrema.ParOnFaceS2(1, u, v );
break;
}
case BRepExtrema_IsOnEdge: {
TopoDS_Edge edge = TopoDS::Edge( extrema.SupportOnShape2(1));
Handle(Geom2d_Curve) pcurve = BRep_Tool::CurveOnSurface( edge, face, f,l );
extrema.ParOnEdgeS2( 1, u );
gp_Pnt2d uv = pcurve->Value( u );
u = uv.Coord(1);
v = uv.Coord(2);
break;
}
case BRepExtrema_IsVertex: return defaultNorm;
}
// get derivatives
BRepAdaptor_Surface surface( face, false );
gp_Vec du, dv; gp_Pnt p;
surface.D1( u, v, p, du, dv );
return du ^ dv;
} catch (Standard_Failure ) {
}
return defaultNorm;
}
void AddFlatSubShapes(const TopoDS_Shape& S, TopTools_ListOfShape& L, TopTools_MapOfShape& M)
{
if (S.ShapeType() != TopAbs_COMPOUND) {
L.Append(S);
}
else {
TopoDS_Iterator It(S, Standard_True, Standard_True);
for (; It.More(); It.Next()) {
TopoDS_Shape SS = It.Value();
if (M.Add(SS))
AddFlatSubShapes(SS, L, M);
}
}
}
}
//============================================================================= //=============================================================================
/*! /*!
@ -1298,17 +1355,20 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::MakeExplode
TopTools_ListOfShape listShape; TopTools_ListOfShape listShape;
if (aShape.ShapeType() == TopAbs_COMPOUND && if (aShape.ShapeType() == TopAbs_COMPOUND &&
(TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE || (theShapeType == TopAbs_SHAPE || theShapeType == TopAbs_FLAT || theShapeType == TopAbs_COMPOUND))
TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPSOLID ||
TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND))
{ {
TopoDS_Iterator It (aShape, Standard_True, Standard_True); TopoDS_Iterator It (aShape, Standard_True, Standard_True);
for (; It.More(); It.Next()) { for (; It.More(); It.Next()) {
if (mapShape.Add(It.Value())) { TopoDS_Shape SS = It.Value();
if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE || if (mapShape.Add(SS)) {
TopAbs_ShapeEnum(theShapeType) == It.Value().ShapeType()) { if (theShapeType == TopAbs_FLAT) {
listShape.Append(It.Value()); AddFlatSubShapes(SS, listShape, mapShape);
}
else if (theShapeType == TopAbs_SHAPE || theShapeType == SS.ShapeType()) {
listShape.Append(SS);
} }
// VSR: for EXPLODE_NEW_INCLUDE_MAIN and EXPLODE_OLD_INCLUDE_MAIN:
// it seems it is necessary to add top-level shape if theShapeType == TopAbs_COMPOUND
} }
} }
} }
@ -1320,7 +1380,7 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::MakeExplode
listShape.Append(exp.Current()); listShape.Append(exp.Current());
} }
if (listShape.IsEmpty()) { if (listShape.IsEmpty()){
//SetErrorCode("The given shape has no sub-shapes of the requested type"); //SetErrorCode("The given shape has no sub-shapes of the requested type");
SetErrorCode(NOT_FOUND_ANY); // NPAL18017 SetErrorCode(NOT_FOUND_ANY); // NPAL18017
return aSeq; return aSeq;
@ -1364,16 +1424,15 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::MakeExplode
// Put this subshape in the list of sub-shapes of theMainShape // Put this subshape in the list of sub-shapes of theMainShape
aMainShape->AddSubShapeReference(aFunction); aMainShape->AddSubShapeReference(aFunction);
} }
if (!anObj.IsNull()) { if (!anObj.IsNull()) {
aSeq->Append(anObj); aSeq->Append(anObj);
// for python command // for python command
TDF_Tool::Entry(anObj->GetEntry(), anEntry); TDF_Tool::Entry(anObj->GetEntry(), anEntry);
anAsciiList += anEntry; anAsciiList += anEntry;
anAsciiList += ","; anAsciiList += ",";
} }
} }
//Make a Python command //Make a Python command
anAsciiList.Trunc(anAsciiList.Length() - 1); anAsciiList.Trunc(anAsciiList.Length() - 1);
@ -1422,16 +1481,17 @@ Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::SubShapeAllIDs
TopTools_ListOfShape listShape; TopTools_ListOfShape listShape;
if (aShape.ShapeType() == TopAbs_COMPOUND && if (aShape.ShapeType() == TopAbs_COMPOUND &&
(TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE || (theShapeType == TopAbs_SHAPE || theShapeType == TopAbs_FLAT || theShapeType == TopAbs_COMPOUND))
TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPSOLID ||
TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND))
{ {
TopoDS_Iterator It (aShape, Standard_True, Standard_True); TopoDS_Iterator It (aShape, Standard_True, Standard_True);
for (; It.More(); It.Next()) { for (; It.More(); It.Next()) {
if (mapShape.Add(It.Value())) { TopoDS_Shape SS = It.Value();
if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE || if (mapShape.Add(SS)) {
TopAbs_ShapeEnum(theShapeType) == It.Value().ShapeType()) { if (theShapeType == TopAbs_FLAT) {
listShape.Append(It.Value()); AddFlatSubShapes(SS, listShape, mapShape);
}
else if (theShapeType == TopAbs_SHAPE || theShapeType == SS.ShapeType()) {
listShape.Append(SS);
} }
} }
} }
@ -1850,33 +1910,41 @@ Standard_Integer GEOMImpl_IShapesOperations::NumberOfSubShapes
*/ */
try { try {
OCC_CATCH_SIGNALS; if (theShapeType == TopAbs_FLAT) {
int iType, nbTypes [TopAbs_SHAPE]; TopTools_MapOfShape aMapOfShape;
for (iType = 0; iType < TopAbs_SHAPE; ++iType) TopTools_ListOfShape aListOfShape;
nbTypes[iType] = 0; AddFlatSubShapes(aShape, aListOfShape, aMapOfShape);
nbTypes[aShape.ShapeType()]++; nbShapes = aListOfShape.Extent();
}
else {
OCC_CATCH_SIGNALS;
int iType, nbTypes [TopAbs_SHAPE];
for (iType = 0; iType < TopAbs_SHAPE; ++iType)
nbTypes[iType] = 0;
nbTypes[aShape.ShapeType()]++;
TopTools_MapOfShape aMapOfShape; TopTools_MapOfShape aMapOfShape;
aMapOfShape.Add(aShape); aMapOfShape.Add(aShape);
TopTools_ListOfShape aListOfShape; TopTools_ListOfShape aListOfShape;
aListOfShape.Append(aShape); aListOfShape.Append(aShape);
TopTools_ListIteratorOfListOfShape itL (aListOfShape); TopTools_ListIteratorOfListOfShape itL (aListOfShape);
for (; itL.More(); itL.Next()) { for (; itL.More(); itL.Next()) {
TopoDS_Iterator it (itL.Value()); TopoDS_Iterator it (itL.Value());
for (; it.More(); it.Next()) { for (; it.More(); it.Next()) {
TopoDS_Shape s = it.Value(); TopoDS_Shape s = it.Value();
if (aMapOfShape.Add(s)) { if (aMapOfShape.Add(s)) {
aListOfShape.Append(s); aListOfShape.Append(s);
nbTypes[s.ShapeType()]++; nbTypes[s.ShapeType()]++;
}
} }
} }
}
if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE) if (TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE)
nbShapes = aMapOfShape.Extent(); nbShapes = aMapOfShape.Extent();
else else
nbShapes = nbTypes[theShapeType]; nbShapes = nbTypes[theShapeType];
}
} }
catch (Standard_Failure) { catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught(); Handle(Standard_Failure) aFail = Standard_Failure::Caught();
@ -3850,49 +3918,6 @@ void GEOMImpl_IShapesOperations::GetShapeProperties( const TopoDS_Shape aShape,
return; return;
} }
namespace {
//================================================================================
/*!
* \brief Return normal to face at extrema point
*/
//================================================================================
gp_Vec GetNormal (const TopoDS_Face& face, const BRepExtrema_DistShapeShape& extrema)
{
gp_Vec defaultNorm(1,0,0); // to have same normals on different faces
try {
// get UV at extrema point
Standard_Real u,v, f,l;
switch ( extrema.SupportTypeShape2(1) ) {
case BRepExtrema_IsInFace: {
extrema.ParOnFaceS2(1, u, v );
break;
}
case BRepExtrema_IsOnEdge: {
TopoDS_Edge edge = TopoDS::Edge( extrema.SupportOnShape2(1));
Handle(Geom2d_Curve) pcurve = BRep_Tool::CurveOnSurface( edge, face, f,l );
extrema.ParOnEdgeS2( 1, u );
gp_Pnt2d uv = pcurve->Value( u );
u = uv.Coord(1);
v = uv.Coord(2);
break;
}
case BRepExtrema_IsVertex: return defaultNorm;
}
// get derivatives
BRepAdaptor_Surface surface( face, false );
gp_Vec du, dv; gp_Pnt p;
surface.D1( u, v, p, du, dv );
return du ^ dv;
} catch (Standard_Failure ) {
}
return defaultNorm;
}
}
//============================================================================= //=============================================================================
/*! /*!
* case GetInPlace: * case GetInPlace:

View File

@ -20,6 +20,10 @@
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
// //
#ifndef GEOMImpl_Types_HXX
#define GEOMImpl_Types_HXX
#include <TopAbs_ShapeEnum.hxx>
// GEOM_Object types // GEOM_Object types
@ -371,5 +375,10 @@
#define USER_TYPE_EX 1000 // Base type for GEOM plugins #define USER_TYPE_EX 1000 // Base type for GEOM plugins
//Plugins specified constants // Plugins specified constants
#define PLUGIN_NAME "Plugin Name" #define PLUGIN_NAME "Plugin Name"
// Flat type for TopAbs
enum { TopAbs_FLAT = TopAbs_SHAPE+1 };
#endif // GEOMImpl_Types_HXX

View File

@ -559,7 +559,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
## Enumeration ShapeType as a dictionary. \n ## Enumeration ShapeType as a dictionary. \n
## Topological types of shapes (like Open Cascade types). See GEOM::shape_type for details. ## Topological types of shapes (like Open Cascade types). See GEOM::shape_type for details.
# @ingroup l1_geomBuilder_auxiliary # @ingroup l1_geomBuilder_auxiliary
ShapeType = {"AUTO":-1, "COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE":5, "EDGE":6, "VERTEX":7, "SHAPE":8} ShapeType = {"AUTO":-1, "COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE":5, "EDGE":6, "VERTEX":7, "SHAPE":8, "FLAT":9}
## Kinds of shape in terms of <VAR>GEOM.GEOM_IKindOfShape.shape_kind</VAR> enumeration ## Kinds of shape in terms of <VAR>GEOM.GEOM_IKindOfShape.shape_kind</VAR> enumeration
# and a list of parameters, describing the shape. # and a list of parameters, describing the shape.