Loading files
f2929057eThis file is pinned to the selected release. Download the original to open it in your design tool.
// Copyright (c) 1999-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 <BRep_Builder.hxx>
#include <BRepGProp.hxx>
#include <GProp_GProps.hxx>
#include <Precision.hxx>
#include <ShapeBuild_ReShape.hxx>
#include <ShapeExtend.hxx>
#include <ShapeUpgrade_FaceDivideArea.hxx>
#include <ShapeUpgrade_SplitSurfaceArea.hxx>
#include <Standard_Type.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
IMPLEMENT_STANDARD_RTTIEXT(ShapeUpgrade_FaceDivideArea, ShapeUpgrade_FaceDivide)
//=================================================================================================
ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea()
{
myMaxArea = Precision::Infinite();
myNbParts = 0;
myUnbSplit = myVnbSplit = -1;
myIsSplittingByNumber = false;
SetPrecision(1.e-5);
SetSplitSurfaceTool(new ShapeUpgrade_SplitSurfaceArea);
}
//=================================================================================================
ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea(const TopoDS_Face& F)
{
myMaxArea = Precision::Infinite();
myNbParts = 0;
myUnbSplit = myVnbSplit = -1;
myIsSplittingByNumber = false;
SetPrecision(1.e-5);
SetSplitSurfaceTool(new ShapeUpgrade_SplitSurfaceArea);
Init(F);
}
//=================================================================================================
bool ShapeUpgrade_FaceDivideArea::Perform(const double)
{
myStatus = ShapeExtend::EncodeStatus(ShapeExtend_OK);
GProp_GProps aGprop;
BRepGProp::SurfaceProperties(myFace, aGprop, Precision());
double anArea = aGprop.Mass();
int anbParts = 0;
if (myMaxArea == -1)
{
anbParts = myNbParts;
myMaxArea = anArea / anbParts;
}
if ((anArea - myMaxArea) < Precision::Confusion())
{
return false;
}
if (anbParts == 0)
{
anbParts = RealToInt(ceil(anArea / myMaxArea));
}
occ::handle<ShapeUpgrade_SplitSurfaceArea> aSurfTool =
occ::down_cast<ShapeUpgrade_SplitSurfaceArea>(GetSplitSurfaceTool());
if (aSurfTool.IsNull())
{
return false;
}
aSurfTool->NbParts() = anbParts;
if (myIsSplittingByNumber)
{
aSurfTool->SetSplittingIntoSquares(true);
aSurfTool->SetNumbersUVSplits(myUnbSplit, myVnbSplit);
}
if (!ShapeUpgrade_FaceDivide::Perform(anArea))
{
return false;
}
TopoDS_Shape aResult = Result();
if (aResult.ShapeType() == TopAbs_FACE)
{
return false;
}
int aStatus = myStatus;
if (!myIsSplittingByNumber)
{
TopExp_Explorer aExpF(aResult, TopAbs_FACE);
TopoDS_Shape aCopyRes = aResult.EmptyCopied();
bool isModified = false;
for (; aExpF.More(); aExpF.Next())
{
TopoDS_Shape aSh = Context()->Apply(aExpF.Current());
TopoDS_Face aFace = TopoDS::Face(aSh);
Init(aFace);
BRep_Builder aB;
if (Perform())
{
isModified = true;
TopoDS_Shape aRes = Result();
TopExp_Explorer aExpR(aRes, TopAbs_FACE);
for (; aExpR.More(); aExpR.Next())
{
aB.Add(aCopyRes, aExpR.Current());
}
}
else
{
aB.Add(aCopyRes, aFace);
}
}
if (isModified)
{
if (aCopyRes.ShapeType() == TopAbs_WIRE || aCopyRes.ShapeType() == TopAbs_SHELL)
{
aCopyRes.Closed(BRep_Tool::IsClosed(aCopyRes));
}
Context()->Replace(aResult, aCopyRes);
}
}
myStatus |= aStatus;
myResult = Context()->Apply(aResult);
return Status(ShapeExtend_DONE);
}