Loading files
3d097a032This file is pinned to the selected release. Download the original to open it in your design tool.
// Created on: 2000-02-01
// Created by: Peter KURNEV
// Copyright (c) 2000-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <TopExp.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopOpeBRepBuild_GTopo.hxx>
#include <TopOpeBRepBuild_HBuilder.hxx>
#include <TopOpeBRepBuild_PaveSet.hxx>
#include <TopOpeBRepBuild_WireEdgeSet.hxx>
#include <TopOpeBRepDS_CurveExplorer.hxx>
#include <TopOpeBRepDS_HDataStructure.hxx>
#include <TopTools_ShapeMapHasher.hxx>
#include <NCollection_IndexedDataMap.hxx>
#include <NCollection_IndexedMap.hxx>
#include <NCollection_List.hxx>
//=======================================================================
// function : TopOpeBRepBuild_Builder1::CorrectResult2d
// purpose : Change the Result (after CorrectFace2d)
//=======================================================================
int TopOpeBRepBuild_Builder1::CorrectResult2d(TopoDS_Shape& aResult)
{
int aNb = myMapOfCorrect2dEdges.Extent();
if (!aNb)
{
return 0;
}
if (aResult.ShapeType() != TopAbs_SOLID)
{
return 0;
}
//
// 1. Map Of sources' subshapes .
// The map (aSourceShapeMap) is to prevent unnecessary coping
NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> aSourceShapeMap;
TopExp::MapShapes(myShape1, TopAbs_EDGE, aSourceShapeMap);
TopExp::MapShapes(myShape2, TopAbs_EDGE, aSourceShapeMap);
NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> EdMap;
BRep_Builder BB;
TopoDS_Shape aLocalShape = aResult.EmptyCopied();
TopoDS_Solid aSolid = TopoDS::Solid(aLocalShape);
// TopoDS_Solid aSolid=TopoDS::Solid(aResult.EmptyCopied());
TopExp_Explorer anExpShells(aResult, TopAbs_SHELL);
for (; anExpShells.More(); anExpShells.Next())
{
const TopoDS_Shell& S = TopoDS::Shell(anExpShells.Current());
aLocalShape = S.EmptyCopied();
TopoDS_Shell aShell = TopoDS::Shell(aLocalShape);
// TopoDS_Shell aShell=TopoDS::Shell(S.EmptyCopied());
TopExp_Explorer anExpFaces(S, TopAbs_FACE);
for (; anExpFaces.More(); anExpFaces.Next())
{
TopoDS_Face F = TopoDS::Face(anExpFaces.Current());
// modified by NIZHNY-MZV Mon Mar 27 09:51:59 2000
TopAbs_Orientation Fori = F.Orientation();
// we should explore FORWARD face
// F.Orientation(TopAbs_FORWARD);
aLocalShape = F.EmptyCopied();
TopoDS_Face aFace = TopoDS::Face(aLocalShape);
// TopoDS_Face aFace=TopoDS::Face(F.EmptyCopied());
TopExp_Explorer anExpWires(F, TopAbs_WIRE);
for (; anExpWires.More(); anExpWires.Next())
{
TopoDS_Wire W = TopoDS::Wire(anExpWires.Current());
// modified by NIZHNY-MZV Mon Mar 27 09:51:59 2000
TopAbs_Orientation Wori = W.Orientation();
// we should explore FORWARD wire
// W.Orientation(TopAbs_FORWARD);
aLocalShape = W.EmptyCopied();
TopoDS_Wire aWire = TopoDS::Wire(aLocalShape);
// TopoDS_Wire aWire = TopoDS::Wire(W.EmptyCopied());
TopExp_Explorer anExpEdges(W, TopAbs_EDGE);
for (; anExpEdges.More(); anExpEdges.Next())
{
TopoDS_Edge E = TopoDS::Edge(anExpEdges.Current());
if (EdMap.Contains(E))
{
TopoDS_Shape anEdge = EdMap.ChangeFromKey(E);
anEdge.Orientation(E.Orientation());
BB.Add(aWire, anEdge);
continue;
}
if (myMapOfCorrect2dEdges.Contains(E))
{
TopoDS_Shape anEdge = myMapOfCorrect2dEdges.ChangeFromKey(E);
anEdge.Orientation(E.Orientation());
BB.Add(aWire, anEdge);
EdMap.Add(E, anEdge);
continue;
}
// add edges
TopoDS_Edge anEdge;
// we copy edge in order to not change it in source shapes
if (aSourceShapeMap.Contains(E))
{
TopoDS_Shape aLocalShape1 = E.EmptyCopied();
anEdge = TopoDS::Edge(aLocalShape1);
// anEdge = TopoDS::Edge(E.EmptyCopied());
EdMap.Add(E, anEdge);
TopExp_Explorer anExpVertices(E, TopAbs_VERTEX);
bool free = anEdge.Free();
anEdge.Free(true);
for (; anExpVertices.More(); anExpVertices.Next())
{
BB.Add(anEdge, anExpVertices.Current());
}
anEdge.Free(free);
}
else
{
anEdge = E;
}
anEdge.Orientation(E.Orientation());
BB.Add(aWire, anEdge);
}
// Add wires
aWire.Orientation(Wori);
aWire.Closed(BRep_Tool::IsClosed(aWire));
BB.Add(aFace, aWire);
}
aFace.Orientation(Fori);
BB.Add(aShell, aFace);
}
aShell.Orientation(S.Orientation());
aShell.Closed(BRep_Tool::IsClosed(aShell));
BB.Add(aSolid, aShell);
}
aResult = aSolid;
// update section curves
TopOpeBRepDS_CurveExplorer cex(myDataStructure->DS());
for (; cex.More(); cex.Next())
{
int ic = cex.Index();
NCollection_List<TopoDS_Shape>& LSE = ChangeNewEdges(ic);
NCollection_List<TopoDS_Shape> corrLSE;
NCollection_List<TopoDS_Shape>::Iterator it(LSE);
for (; it.More(); it.Next())
{
const TopoDS_Shape& E = it.Value();
if (EdMap.Contains(E))
{
const TopoDS_Shape& newE = EdMap.FindFromKey(E);
corrLSE.Append(newE);
}
else
{
corrLSE.Append(E);
}
}
LSE.Clear();
LSE.Append(corrLSE);
}
// update section edges
const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
int i, nes = BDS.NbSectionEdges();
for (i = 1; i <= nes; i++)
{
const TopoDS_Shape& es = BDS.SectionEdge(i);
if (es.IsNull())
{
continue;
}
for (int j = 0; j <= 2; j++)
{
TopAbs_State staspl = TopAbs_State(j); // 0 - IN, 1 - OUT, 2 - ON
NCollection_List<TopoDS_Shape>& LSE = ChangeSplit(es, staspl);
NCollection_List<TopoDS_Shape> corrLSE;
NCollection_List<TopoDS_Shape>::Iterator it(LSE);
for (; it.More(); it.Next())
{
const TopoDS_Shape& E = it.Value();
if (EdMap.Contains(E))
{
const TopoDS_Shape& newE = EdMap.FindFromKey(E);
corrLSE.Append(newE);
}
else
{
corrLSE.Append(E);
}
}
LSE.Clear();
LSE.Append(corrLSE);
}
}
return 1;
}