-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 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.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4786 )
#endif
#include <GEOMImpl_BlockDriver.hxx>
#include <GEOMImpl_IBlocks.hxx>
#include <GEOMImpl_IBlockTrsf.hxx>
-#include <GEOMImpl_CopyDriver.hxx>
#include <GEOMImpl_Block6Explorer.hxx>
-#include <GEOMImpl_IShapesOperations.hxx>
+
+#include <GEOMUtils.hxx>
#include <GEOM_Function.hxx>
#include <GEOM_PythonDump.hxx>
//Compute the Face value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Block driver failed to compute a face");
return NULL;
//Compute the Face value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Block driver failed to compute a face");
return NULL;
//Compute the Face value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Block driver failed to compute a face");
return NULL;
//Compute the Block value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Block driver failed to compute a block");
return NULL;
//Compute the Block value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Block driver failed to compute a block");
return NULL;
//Compute the Blocks Compound value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Block driver failed to compute a blocks compound");
return NULL;
anArray->SetValue(1, anIndices.FindIndex(V));
aResult = GetEngine()->AddSubShape(theShape, anArray);
- // The GetPoint() doesn't change object so no new function is required.
- Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
+ Handle(GEOM_Function) aFunction = aResult->GetLastFunction();
// Make a Python command
- GEOM::TPythonDump(aFunction, /*append=*/true)
- << aResult << " = geompy.GetVertexNearPoint("
- << theShape << ", " << thePoint << ")";
+ GEOM::TPythonDump(aFunction) << aResult << " = geompy.GetVertexNearPoint("
+ << theShape << ", " << thePoint << ")";
SetErrorCode(OK);
return aResult;
//Compute the Edge value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
TopTools_IndexedDataMapOfShapeListOfShape MVE;
GEOMImpl_Block6Explorer::MapShapesAndAncestors
(aBlockOrComp, TopAbs_VERTEX, TopAbs_EDGE, MVE);
//Compute the Edge value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
- TopoDS_Shape aShape;
-
TopoDS_Vertex aVert = TopoDS::Vertex(anArg);
+ TopoDS_Shape aShape = GEOMUtils::GetEdgeNearPoint(aBlockOrComp, aVert);
- // 1. Explode blocks on edges
- TopTools_MapOfShape mapShape;
- Standard_Integer nbEdges = 0;
- TopExp_Explorer exp (aBlockOrComp, TopAbs_EDGE);
- for (; exp.More(); exp.Next()) {
- if (mapShape.Add(exp.Current())) {
- nbEdges++;
- }
- }
-
- if (nbEdges == 0) {
- SetErrorCode("Given shape contains no edges");
- return NULL;
- }
-
- mapShape.Clear();
- Standard_Integer ind = 1;
- TopTools_Array1OfShape anEdges (1, nbEdges);
- TColStd_Array1OfReal aDistances (1, nbEdges);
- for (exp.Init(aBlockOrComp, TopAbs_EDGE); exp.More(); exp.Next()) {
- if (mapShape.Add(exp.Current())) {
- TopoDS_Shape anEdge = exp.Current();
- anEdges(ind) = anEdge;
-
- // 2. Classify the point relatively each edge
- BRepExtrema_DistShapeShape aDistTool (aVert, anEdges(ind));
- if (!aDistTool.IsDone()) {
- SetErrorCode("Can not find a distance from the given point to one of edges");
- return NULL;
- }
- aDistances(ind) = aDistTool.Value();
- ind++;
- }
- }
-
- // 3. Define edge, having minimum distance to the point
- Standard_Real nearest = RealLast(), nbFound = 0;
- Standard_Real prec = Precision::Confusion();
- for (ind = 1; ind <= nbEdges; ind++) {
- if (Abs(aDistances(ind) - nearest) < prec) {
- nbFound++;
- } else if (aDistances(ind) < nearest) {
- nearest = aDistances(ind);
- aShape = anEdges(ind);
- nbFound = 1;
- } else {
- }
- }
- if (nbFound > 1) {
- SetErrorCode("Multiple edges near the given point are found");
- return NULL;
- } else if (nbFound == 0) {
- SetErrorCode("There are no edges near the given point");
- return NULL;
- } else {
- TopTools_IndexedMapOfShape anIndices;
- TopExp::MapShapes(aBlockOrComp, anIndices);
- Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1,1);
- anArray->SetValue(1, anIndices.FindIndex(aShape));
- aResult = GetEngine()->AddSubShape(theShape, anArray);
- }
+ TopTools_IndexedMapOfShape anIndices;
+ TopExp::MapShapes(aBlockOrComp, anIndices);
+ Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1,1);
+ anArray->SetValue(1, anIndices.FindIndex(aShape));
+ aResult = GetEngine()->AddSubShape(theShape, anArray);
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
//Compute the Face value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
TopoDS_Shape aShape;
TopTools_IndexedDataMapOfShapeListOfShape MVF;
//Compute the Face value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
TopoDS_Shape aShape;
TopTools_IndexedDataMapOfShapeListOfShape MEF;
//Compute the Face value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
TopoDS_Shape aShape;
GEOMImpl_Block6Explorer aBlockTool;
//Compute the Face value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
TopoDS_Shape aShape;
TopoDS_Vertex aVert = TopoDS::Vertex(anArg);
//Compute the Face value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
TopoDS_Shape aShape;
TopoDS_Edge anEdge = TopoDS::Edge(anArg);
// Compute the result
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
TopoDS_Vertex aVert = TopoDS::Vertex(anArg);
TopTools_MapOfShape mapShape;
//Check
isCompOfBlocks = Standard_True;
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
TopTools_MapOfShape mapShape;
TopExp_Explorer exp (aBlockOrComp, TopAbs_SOLID);
for (; exp.More(); exp.Next()) {
void GEOMImpl_IBlocksOperations::AddBlocksFrom (const TopoDS_Shape& theShape,
TopTools_ListOfShape& BLO,
TopTools_ListOfShape& NOT,
- TopTools_ListOfShape& EXT)
+ TopTools_ListOfShape& EXT,
+ TopTools_ListOfShape& NOQ)
{
TopAbs_ShapeEnum aType = theShape.ShapeType();
switch (aType) {
{
TopoDS_Iterator It (theShape);
for (; It.More(); It.Next()) {
- AddBlocksFrom(It.Value(), BLO, NOT, EXT);
+ AddBlocksFrom(It.Value(), BLO, NOT, EXT, NOQ);
}
}
break;
for (; expF.More(); expF.Next()) {
if (mapFaces.Add(expF.Current())) {
nbFaces++;
- if (nbFaces > 6) break;
+ //0021483//if (nbFaces > 6) break;
// get wire
TopoDS_Shape aF = expF.Current();
if (!wires.More()) {
// no wire in the face
hasNonQuadr = Standard_True;
- break;
+ NOQ.Append(aF);//0021483
+ //0021483//break;
+ continue;
}
TopoDS_Shape aWire = wires.Current();
wires.Next();
if (wires.More()) {
// multiple wires in the face
hasNonQuadr = Standard_True;
- break;
+ NOQ.Append(aF);//0021483
+ //0021483//break;
+ continue;
}
// Check number of edges in the face
}
if (nbEdges != 4) {
hasNonQuadr = Standard_True;
+ NOQ.Append(aF);//0021483
}
}
}
}
}
break;
+ case TopAbs_SHELL: //0021483
+ case TopAbs_FACE: //0021483
+ {
+ // Count edges in each face
+ TopTools_MapOfShape mapFaces;
+ TopExp_Explorer expF (theShape, TopAbs_FACE);
+ for (; expF.More(); expF.Next()) {
+ if (mapFaces.Add(expF.Current())) {
+ // get wire
+ TopoDS_Shape aF = expF.Current();
+ TopExp_Explorer wires (aF, TopAbs_WIRE);
+ if (!wires.More()) {
+ // no wire in the face
+ NOQ.Append(aF);//0021483
+ continue;
+ }
+ TopoDS_Shape aWire = wires.Current();
+ wires.Next();
+ if (wires.More()) {
+ // multiple wires in the face
+ NOQ.Append(aF);//0021483
+ continue;
+ }
+
+ // Check number of edges in the face
+ Standard_Integer nbEdges = 0;
+ TopTools_MapOfShape mapEdges;
+ TopExp_Explorer expW (aWire, TopAbs_EDGE);
+ for (; expW.More(); expW.Next()) {
+ if (mapEdges.Add(expW.Current())) {
+ nbEdges++;
+ if (nbEdges > 4) break;
+ }
+ }
+ if (nbEdges != 4) {
+ NOQ.Append(aF);//0021483
+ }
+ }
+ }
+ }
+ break;
default:
NOT.Append(theShape);
}
TopTools_ListOfShape NOT; // Not blocks
TopTools_ListOfShape EXT; // Hexahedral solids, having degenerated and/or seam edges
TopTools_ListOfShape BLO; // All blocks from the given compound
- AddBlocksFrom(aBlockOrComp, BLO, NOT, EXT);
+ TopTools_ListOfShape NOQ; // All non-quadrangular faces
+ AddBlocksFrom(aBlockOrComp, BLO, NOT, EXT, NOQ);
// Report non-blocks
if (NOT.Extent() > 0) {
return isCompOfBlocks;
}
+//=============================================================================
+/*!
+ * GetNonBlocks
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_IBlocksOperations::GetNonBlocks
+ (Handle(GEOM_Object) theShape,
+ Handle(GEOM_Object)& theNonQuads)
+{
+ SetErrorCode(KO);
+
+ if (theShape.IsNull()) return NULL;
+ TopoDS_Shape aShape = theShape->GetValue();
+
+ // Separate blocks from non-blocks
+ TopTools_ListOfShape BLO; // All blocks from the given compound
+ TopTools_ListOfShape NOT; // Not blocks
+ TopTools_ListOfShape EXT; // Hexahedral solids, having degenerated and/or seam edges
+ TopTools_ListOfShape NOQ; // All non-quadrangular faces
+ AddBlocksFrom(aShape, BLO, NOT, EXT, NOQ);
+
+ if (NOT.IsEmpty() && EXT.IsEmpty() && NOQ.IsEmpty()) {
+ SetErrorCode("NOT_FOUND_ANY");
+ return NULL;
+ }
+
+ // Map sub-shapes and their indices
+ TopTools_IndexedMapOfShape anIndices;
+ TopExp::MapShapes(aShape, anIndices);
+
+ // Non-blocks
+ Handle(GEOM_Object) aNonBlocks;
+ if (NOT.Extent() > 0 || EXT.Extent() > 0) {
+ Handle(TColStd_HArray1OfInteger) anArray =
+ new TColStd_HArray1OfInteger (1, NOT.Extent() + EXT.Extent());
+ Standard_Integer ii = 1;
+ TopTools_ListIteratorOfListOfShape it1 (NOT);
+ for (; it1.More(); it1.Next(), ii++) {
+ anArray->SetValue(ii, anIndices.FindIndex(it1.Value()));
+ }
+ TopTools_ListIteratorOfListOfShape it2 (EXT);
+ for (; it2.More(); it2.Next(), ii++) {
+ anArray->SetValue(ii, anIndices.FindIndex(it2.Value()));
+ }
+
+ aNonBlocks = GetEngine()->AddSubShape(theShape, anArray);
+ if (aNonBlocks.IsNull()) {
+ SetErrorCode("Error in algorithm: result found, but cannot be returned.");
+ return NULL;
+ }
+ aNonBlocks->SetType(GEOM_GROUP);
+ TDF_Label aFreeLabel = aNonBlocks->GetFreeLabel();
+ TDataStd_Integer::Set(aFreeLabel, (Standard_Integer)TopAbs_SOLID);
+ }
+
+ // Non-quadrangles
+ if (NOQ.Extent() > 0) {
+ Handle(TColStd_HArray1OfInteger) anArray =
+ new TColStd_HArray1OfInteger (1, NOQ.Extent());
+ Standard_Integer ii = 1;
+ TopTools_ListIteratorOfListOfShape it1 (NOQ);
+ for (; it1.More(); it1.Next(), ii++) {
+ anArray->SetValue(ii, anIndices.FindIndex(it1.Value()));
+ }
+
+ theNonQuads = GetEngine()->AddSubShape(theShape, anArray);
+ if (theNonQuads.IsNull()) {
+ SetErrorCode("Error in algorithm: result found, but cannot be returned.");
+ return NULL;
+ }
+ theNonQuads->SetType(GEOM_GROUP);
+ TDF_Label aFreeLabel = theNonQuads->GetFreeLabel();
+ TDataStd_Integer::Set(aFreeLabel, (Standard_Integer)TopAbs_FACE);
+ }
+
+ //Make a Python command
+ Handle(GEOM_Function) aMainShape = theShape->GetLastFunction();
+ GEOM::TPythonDump pd (aMainShape, /*append=*/true);
+ pd << "(";
+ if (aNonBlocks.IsNull())
+ pd << "no_bad_solids";
+ else
+ pd << aNonBlocks;
+ pd << ", ";
+ if (theNonQuads.IsNull())
+ pd << "no_bad_faces";
+ else
+ pd << theNonQuads;
+ pd << ") = geompy.GetNonBlocks(" << theShape << ")";
+
+ SetErrorCode(OK);
+ return aNonBlocks;
+}
+
//=============================================================================
/*!
* RemoveExtraEdges
//Compute the fixed shape
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Block driver failed to remove extra edges of the given shape");
return NULL;
return aCopy;
}
+//=============================================================================
+/*!
+ * UnionFaces
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_IBlocksOperations::UnionFaces
+ (Handle(GEOM_Object) theObject)
+{
+ SetErrorCode(KO);
+
+ if (theObject.IsNull()) return NULL;
+
+ Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
+ if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be fixed
+
+ //Add a new Copy object
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), GEOM_COPY);
+
+ //Add a function
+ Handle(GEOM_Function) aFunction =
+ aCopy->AddFunction(GEOMImpl_BlockDriver::GetID(), BLOCK_UNION_FACES);
+
+ //Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_BlockDriver::GetID()) return NULL;
+
+ GEOMImpl_IBlockTrsf aTI (aFunction);
+ aTI.SetOriginal(aLastFunction);
+
+ //Compute the fixed shape
+ try {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Block driver failed to remove extra edges of the given shape");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure) {
+ Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+ SetErrorCode(aFail->GetMessageString());
+ return NULL;
+ }
+
+ //Make a Python command
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.UnionFaces("
+ << theObject << ")";
+
+ SetErrorCode(OK);
+ return aCopy;
+}
+
//=============================================================================
/*!
* CheckAndImprove
//Compute the fixed shape
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Block driver failed to improve the given blocks compound");
return NULL;
// Explode
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
TopExp_Explorer exp (aBlockOrComp, TopAbs_SOLID);
for (; exp.More(); exp.Next()) {
if (mapShape.Add(exp.Current())) {
//Compute the Block value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
TopoDS_Shape aShape;
TopoDS_Vertex aVert = TopoDS::Vertex(anArg);
//Compute the Block value
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
// 1. Explode compound on solids
TopTools_MapOfShape mapShape;
Standard_Integer nbSolids = 0;
//Get the Blocks
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
TopTools_MapOfShape mapShape;
Standard_Integer nbSolids = 0;
TopExp_Explorer exp (aBlockOrComp, TopAbs_SOLID);
//Compute the transformation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Block driver failed to make multi-transformation");
return NULL;
//Compute the transformation
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Block driver failed to make multi-transformation");
return NULL;
} // while (listPrevEdges.Extent() > 0)
// Sort shapes in current chain (Mantis issue 21053)
- GEOMImpl_IShapesOperations::SortShapes(currentChain, Standard_False);
+ GEOMUtils::SortShapes(currentChain, Standard_False);
aFirstInChains.Append(currentChain.First());
aMapChains.Bind(currentChain.First(), currentChain);
}
// Sort chains (Mantis issue 21053)
- GEOMImpl_IShapesOperations::SortShapes(aFirstInChains, Standard_False);
+ GEOMUtils::SortShapes(aFirstInChains, Standard_False);
// Store sorted chains in the document
TopTools_ListIteratorOfListOfShape aChainsIt (aFirstInChains);