mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-24 13:50:49 +03:00
0031336: Modeling data - extend BRepPrimAPI_MakeBox with planar shape creation
-Create a new package BRepPreviewAPI, inherited from BRepPrimAPI to create both, valid and degenerative shapes -Create a new class BRepPreviewAPI_MakeBox for working with a box Preview can be vertex, edge, rectangle or box -BRepPrim_GWedge: in the case of non-valid data, the exception does not happen in the constructor, but at the moment of access to the shape -BRepPrimAPI_MakeBox: myWedge is now not private, but protected, because used in BRepPreviewAPI_MakeBox which inherits from BRepPrimAPI_MakeBox -Add tests for checking of a creation a preview in tests/geometry/preview (vertex, edge, rectangle, box) -Update a command "box": add new parameters
This commit is contained in:
124
src/BRepPreviewAPI/BRepPreviewAPI_MakeBox.cxx
Normal file
124
src/BRepPreviewAPI/BRepPreviewAPI_MakeBox.cxx
Normal file
@@ -0,0 +1,124 @@
|
||||
// Created on: 2020-01-31
|
||||
// Created by: Svetlana SHUTINA
|
||||
// Copyright (c) 2020 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 <BRepPreviewAPI_MakeBox.hxx>
|
||||
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <BRepBuilderAPI_MakeFace.hxx>
|
||||
#include <BRepBuilderAPI_MakeVertex.hxx>
|
||||
#include <BRepBuilderAPI_MakeWire.hxx>
|
||||
|
||||
#include <TopoDS_Compound.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Build
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void BRepPreviewAPI_MakeBox::Build()
|
||||
{
|
||||
gp_Pnt anLocation = myWedge.Axes().Location();
|
||||
|
||||
gp_Pnt aFirstPoint (anLocation.X(), anLocation.Y(), anLocation.Z());
|
||||
gp_Pnt aSecondPoint (anLocation.X() + myWedge.GetXMax(), anLocation.Y() + myWedge.GetYMax(), anLocation.Z() + myWedge.GetZMax());
|
||||
|
||||
Standard_Boolean aThinOnX = Abs (aFirstPoint.X() - aSecondPoint.X()) < Precision::Confusion();
|
||||
Standard_Boolean aThinOnY = Abs (aFirstPoint.Y() - aSecondPoint.Y()) < Precision::Confusion();
|
||||
Standard_Boolean aThinOnZ = Abs (aFirstPoint.Z() - aSecondPoint.Z()) < Precision::Confusion();
|
||||
|
||||
Standard_Integer aPreviewType = (int)aThinOnX + (int)aThinOnY + (int)aThinOnZ;
|
||||
|
||||
if (aPreviewType == 3) // thin box in all directions is a point
|
||||
{
|
||||
makeVertex (aFirstPoint);
|
||||
}
|
||||
else if (aPreviewType == 2) // thin box in two directions is a point
|
||||
{
|
||||
makeEdge (aFirstPoint, aSecondPoint);
|
||||
}
|
||||
// thin box in only one direction is a rectangular face
|
||||
else if (aPreviewType == 1)
|
||||
{
|
||||
gp_Pnt aPnt1, aPnt2, aPnt3, aPnt4;
|
||||
if (aThinOnX)
|
||||
{
|
||||
aPnt1 = gp_Pnt (aFirstPoint.X(), aFirstPoint.Y(), aFirstPoint.Z());
|
||||
aPnt2 = gp_Pnt (aFirstPoint.X(), aSecondPoint.Y(), aFirstPoint.Z());
|
||||
aPnt3 = gp_Pnt (aFirstPoint.X(), aSecondPoint.Y(), aSecondPoint.Z());
|
||||
aPnt4 = gp_Pnt (aFirstPoint.X(), aFirstPoint.Y(), aSecondPoint.Z());
|
||||
}
|
||||
else if (aThinOnY)
|
||||
{
|
||||
aPnt1 = gp_Pnt (aFirstPoint.X(), aFirstPoint.Y(), aFirstPoint.Z());
|
||||
aPnt2 = gp_Pnt (aSecondPoint.X(), aFirstPoint.Y(), aFirstPoint.Z());
|
||||
aPnt3 = gp_Pnt (aSecondPoint.X(), aFirstPoint.Y(), aSecondPoint.Z());
|
||||
aPnt4 = gp_Pnt (aFirstPoint.X(), aFirstPoint.Y(), aSecondPoint.Z());
|
||||
}
|
||||
else if (aThinOnZ)
|
||||
{
|
||||
aPnt1 = gp_Pnt (aFirstPoint.X(), aFirstPoint.Y(), aFirstPoint.Z());
|
||||
aPnt2 = gp_Pnt (aSecondPoint.X(), aFirstPoint.Y(), aFirstPoint.Z());
|
||||
aPnt3 = gp_Pnt (aSecondPoint.X(), aSecondPoint.Y(), aFirstPoint.Z());
|
||||
aPnt4 = gp_Pnt (aFirstPoint.X(), aSecondPoint.Y(), aFirstPoint.Z());
|
||||
}
|
||||
|
||||
makeRectangle (aPnt1, aPnt2, aPnt3, aPnt4);
|
||||
}
|
||||
|
||||
if (!myShape.IsNull())
|
||||
{
|
||||
Done();
|
||||
return;
|
||||
}
|
||||
|
||||
// box is a valid shape
|
||||
Solid();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : makeVertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void BRepPreviewAPI_MakeBox::makeVertex (const gp_Pnt& thePoint)
|
||||
{
|
||||
myShape = BRepBuilderAPI_MakeVertex (thePoint);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : makeEdge
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void BRepPreviewAPI_MakeBox::makeEdge (const gp_Pnt& thePoint1, const gp_Pnt& thePoint2)
|
||||
{
|
||||
myShape = BRepBuilderAPI_MakeEdge (thePoint1, thePoint2);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : makeRectangle
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void BRepPreviewAPI_MakeBox::makeRectangle (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2,
|
||||
const gp_Pnt& thePnt3, const gp_Pnt& thePnt4)
|
||||
{
|
||||
TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge (thePnt1, thePnt2);
|
||||
TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge (thePnt2, thePnt3);
|
||||
TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge (thePnt3, thePnt4);
|
||||
TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge (thePnt4, thePnt1);
|
||||
|
||||
BRepBuilderAPI_MakeWire aWire (anEdge1, anEdge2, anEdge3, anEdge4);
|
||||
BRepBuilderAPI_MakeFace aFace (aWire);
|
||||
|
||||
myShape = aFace.Shape();
|
||||
}
|
57
src/BRepPreviewAPI/BRepPreviewAPI_MakeBox.hxx
Normal file
57
src/BRepPreviewAPI/BRepPreviewAPI_MakeBox.hxx
Normal file
@@ -0,0 +1,57 @@
|
||||
// Created on: 2020-01-31
|
||||
// Created by: Svetlana SHUTINA
|
||||
// Copyright (c) 2020 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.
|
||||
|
||||
#ifndef _BRepPreviewAPI_MakeBox_HeaderFile
|
||||
#define _BRepPreviewAPI_MakeBox_HeaderFile
|
||||
|
||||
#include <BRepPrimAPI_MakeBox.hxx>
|
||||
|
||||
//! Builds a valid box, if points fulfill the conditions of a valid box.
|
||||
//! And allows to build a preview, otherwise.
|
||||
//! There are 4 cases:
|
||||
//! 1 - preview can be a vertex if thin box in all directions is a point;
|
||||
//! 2 - preview can be an edge if thin box in two directions is a point;
|
||||
//! 3 - preview can be a rectangular face if thin box in only one direction is a point;
|
||||
//! 4 - preview can be a valid box if point values fulfill the conditions of a valid box.
|
||||
|
||||
class BRepPreviewAPI_MakeBox : public BRepPrimAPI_MakeBox
|
||||
{
|
||||
public:
|
||||
|
||||
//! Constructor
|
||||
BRepPreviewAPI_MakeBox() {}
|
||||
|
||||
//! Creates a preview depending on point values.
|
||||
Standard_EXPORT virtual void Build() Standard_OVERRIDE;
|
||||
|
||||
private:
|
||||
|
||||
//! Create a vertex if thin box in all directions is a point.
|
||||
void makeVertex (const gp_Pnt& thePoint);
|
||||
|
||||
//! Create an edge if thin box in two directions is a point.
|
||||
void makeEdge (const gp_Pnt& thePoint1, const gp_Pnt& thePoint2);
|
||||
|
||||
//! Create a rectangular face if the box is thin in one direction only.
|
||||
//! @param thePnt1 the first point for a rectangular face
|
||||
//! @param thePnt2 the second point for a rectangular face
|
||||
//! @param thePnt3 the third point for a rectangular face
|
||||
//! @param thePnt4 the fourth point for a rectangular face
|
||||
void makeRectangle (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2,
|
||||
const gp_Pnt& thePnt3, const gp_Pnt& thePnt4);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
2
src/BRepPreviewAPI/FILES
Normal file
2
src/BRepPreviewAPI/FILES
Normal file
@@ -0,0 +1,2 @@
|
||||
BRepPreviewAPI_MakeBox.hxx
|
||||
BRepPreviewAPI_MakeBox.cxx
|
Reference in New Issue
Block a user