예제 #1
0
void HoleODL::UpdateHole()
{
	if ( !m_NeedUpdate )
	{
		return;
	}

	{
		auto center = HoleSize_ / 2; 
		auto box = BRepPrimAPI_MakeBox(HoleSize_.X(), HoleSize_.Y(), HoleSize_.Z()).Shape();

		gp_Trsf tfs;
		tfs.SetTranslation(center, gp::Origin());
		box.Move(tfs);

		SetBaseShape(box);
	}

	{
		auto offsetSize = HoleSize_ + HoleOffsetSize_;
		auto center = offsetSize / 2; 
		OffsetSizeShape_ = BRepPrimAPI_MakeBox(offsetSize.X(), offsetSize.Y(), offsetSize.Z()).Shape();

		gp_Trsf tfs;
		tfs.SetTranslation(center, gp::Origin());
		OffsetSizeShape_.Move(tfs);
	}

	m_NeedUpdate = false;
}
void TestMkFillet(){
    TopoDS_Shape Box = BRepPrimAPI_MakeBox(10., 10., 10.);
    BRepFilletAPI_MakeFillet mkFillet(Box);

    TopTools_IndexedMapOfShape edges;
    TopExp::MapShapes(Box, TopAbs_EDGE, edges);
    TopoDS_Edge edge = TopoDS::Edge(edges.FindKey(3));

    mkFillet.Add(1., 1., edge);
    mkFillet.Build();

    TopoDS_Shape result = mkFillet.Shape();


    TopTools_IndexedMapOfShape faces;
    TopExp::MapShapes(Box, TopAbs_FACE, faces);
    TopoDS_Face face = TopoDS::Face(faces.FindKey(3));

    TopTools_ListOfShape modified = mkFillet.Modified(face);
    TopTools_ListIteratorOfListOfShape modIt;
    for (int i=1; modIt.More(); modIt.Next(), i++){
        TopoDS_Face curFace = TopoDS::Face(modIt.Value());
        TopoNamingHelper::WriteShape(curFace, "00_02_ModifiedFace", i);
    }

    TopoNamingHelper::WriteShape(result, "00_00_FilletResult");
    TopoNamingHelper::WriteShape(face, "00_01_BaseFace_3");
}
예제 #3
0
void occQt::testCommon()
{
    gp_Ax2 anAxis;
    anAxis.SetLocation(gp_Pnt(0.0, 110.0, 0.0));

    TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0);
    TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 2.5);
    TopoDS_Shape aCommonShape = BRepAlgoAPI_Common(aTopoBox, aTopoSphere);

    gp_Trsf aTrsf;
    aTrsf.SetTranslation(gp_Vec(8.0, 0.0, 0.0));
    BRepBuilderAPI_Transform aTransform(aCommonShape, aTrsf);

    Handle_AIS_Shape anAisBox = new AIS_Shape(aTopoBox);
    Handle_AIS_Shape anAisSphere = new AIS_Shape(aTopoSphere);
    Handle_AIS_Shape anAisCommonShape = new AIS_Shape(aTransform.Shape());

    anAisBox->SetColor(Quantity_NOC_SPRINGGREEN);
    anAisSphere->SetColor(Quantity_NOC_STEELBLUE);
    anAisCommonShape->SetColor(Quantity_NOC_ROYALBLUE);

    mContext->Display(anAisBox);
    mContext->Display(anAisSphere);
    mContext->Display(anAisCommonShape);
}
예제 #4
0
void occQt::testCut()
{
    gp_Ax2 anAxis;
    anAxis.SetLocation(gp_Pnt(0.0, 90.0, 0.0));

    TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0);
    TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 2.5);
    TopoDS_Shape aCuttedShape1 = BRepAlgoAPI_Cut(aTopoBox, aTopoSphere);
    TopoDS_Shape aCuttedShape2 = BRepAlgoAPI_Cut(aTopoSphere, aTopoBox);

    gp_Trsf aTrsf;
    aTrsf.SetTranslation(gp_Vec(8.0, 0.0, 0.0));
    BRepBuilderAPI_Transform aTransform1(aCuttedShape1, aTrsf);

    aTrsf.SetTranslation(gp_Vec(16.0, 0.0, 0.0));
    BRepBuilderAPI_Transform aTransform2(aCuttedShape2, aTrsf);

    Handle_AIS_Shape anAisBox = new AIS_Shape(aTopoBox);
    Handle_AIS_Shape anAisSphere = new AIS_Shape(aTopoSphere);
    Handle_AIS_Shape anAisCuttedShape1 = new AIS_Shape(aTransform1.Shape());
    Handle_AIS_Shape anAisCuttedShape2 = new AIS_Shape(aTransform2.Shape());

    anAisBox->SetColor(Quantity_NOC_SPRINGGREEN);
    anAisSphere->SetColor(Quantity_NOC_STEELBLUE);
    anAisCuttedShape1->SetColor(Quantity_NOC_TAN);
    anAisCuttedShape2->SetColor(Quantity_NOC_SALMON);

    mContext->Display(anAisBox);
    mContext->Display(anAisSphere);
    mContext->Display(anAisCuttedShape1);
    mContext->Display(anAisCuttedShape2);
}
예제 #5
0
void occQt::makeBox()
{
    TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(3.0, 4.0, 5.0);
    Handle_AIS_Shape anAisBox = new AIS_Shape(aTopoBox);

    anAisBox->SetColor(Quantity_NOC_AZURE);

    mContext->Display(anAisBox);
}
예제 #6
0
void CCuboid::MakeTransformedShape(const gp_Trsf &mat)
{
	m_pos.Transform(mat);
	double scale = gp_Vec(1, 0, 0).Transformed(mat).Magnitude();
	m_x = fabs(m_x * scale);
	m_y = fabs(m_y * scale);
	m_z = fabs(m_z * scale);
	m_shape = BRepPrimAPI_MakeBox(m_pos, m_x, m_y, m_z).Shape();
}
예제 #7
0
void occQt::makeFillet()
{
    gp_Ax2 anAxis;
    anAxis.SetLocation(gp_Pnt(0.0, 50.0, 0.0));

    TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0);
    BRepFilletAPI_MakeFillet MF(aTopoBox);

    // Add all the edges to fillet.
    for (TopExp_Explorer ex(aTopoBox, TopAbs_EDGE); ex.More(); ex.Next())
    {
        MF.Add(1.0, TopoDS::Edge(ex.Current()));
    }

    Handle_AIS_Shape anAisShape = new AIS_Shape(MF.Shape());
    anAisShape->SetColor(Quantity_NOC_VIOLET);

    mContext->Display(anAisShape);
}
예제 #8
0
TEST(Standard_StdAllocatorTestSuite, testContainers)
{
    //typed allocator
    std::list<TopoDS_Shape, Standard_StdAllocator<TopoDS_Shape> > aL;
    TopoDS_Solid aSolid = BRepPrimAPI_MakeBox (10., 20., 30.);
    aL.push_back (aSolid);
    ASSERT_EQ(aL.size(), size_t (1));

    //type cast
    Standard_StdAllocator<char> aCAlloc;
    std::vector<int, Standard_StdAllocator<int> > aV (aCAlloc);
    aV.push_back(1);
    ASSERT_EQ(aV.size(), size_t (1));

    //using void-specialization allocator
    std::vector<int, Standard_StdAllocator<void> > aV2;
    aV2.resize(10);
    aV2.push_back(-1);
    ASSERT_EQ(aV2.size(), size_t (11));
}
예제 #9
0
void occQt::makeChamfer()
{
    gp_Ax2 anAxis;
    anAxis.SetLocation(gp_Pnt(8.0, 50.0, 0.0));

    TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0);
    BRepFilletAPI_MakeChamfer MC(aTopoBox);
    TopTools_IndexedDataMapOfShapeListOfShape aEdgeFaceMap;

    TopExp::MapShapesAndAncestors(aTopoBox, TopAbs_EDGE, TopAbs_FACE, aEdgeFaceMap);

    for (Standard_Integer i = 1; i <= aEdgeFaceMap.Extent(); ++i)
    {
        TopoDS_Edge anEdge = TopoDS::Edge(aEdgeFaceMap.FindKey(i));
        TopoDS_Face aFace = TopoDS::Face(aEdgeFaceMap.FindFromIndex(i).First());

        MC.Add(0.6, 0.6, anEdge, aFace);
    }

    Handle_AIS_Shape anAisShape = new AIS_Shape(MC.Shape());
    anAisShape->SetColor(Quantity_NOC_TOMATO);

    mContext->Display(anAisShape);
}
예제 #10
0
void MainWindow::on_drawBox()
{
    TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(3.0, 4.0, 5.0).Shape();

    occView->DrawShape(aTopoBox);
}
TopoShape DuplicateCylinderFilletBug(){
    TopoDS_Shape Box      = BRepPrimAPI_MakeBox(10., 10., 10.);
    TopoDS_Shape Cylinder = BRepPrimAPI_MakeCylinder(2., 10.);

    // in FreeCAD, every operation first creates a blank TopoShape and then adds the
    // TopoDS_Shape to it
    TopoShape BoxShape, CylShape, FusedShape;

    // The current FreeCAD source will directly set TopoShape._Shape from all kinds of
    // places in the code. I have added a TopoShape::setShape method so that we can have
    // some control over this. Note that this method is overloaded a few times
    BoxShape.setShape(Box, "Primitive Box");
    CylShape.setShape(Cylinder, "Primitive Cylinder");

    // As of now, I don't see the TopoShape fuse being used. rather, the fuse is done
    // outside and then stored to the TopoShape
    BRepAlgoAPI_Fuse mkFuse(Box, Cylinder);

    // in my current implementation, I send the FIRST TopoShape from the Fuse operation to
    // the setShape, and copy it's _TopoNamer
    FusedShape.setShape(BoxShape, mkFuse);

    // Now let's select an edge, then fillet it
    TopoDS_Shape BaseShape = mkFuse.Shape();

    // Finaly, 'Select' the edge
    std::string selectionLabel = FusedShape.selectEdge(3);
    std::cout << "Selected Edge Node = " << selectionLabel << std::endl;

    // Write out the current-state of things
    //FusedShape.OCCDeepDump();
    FusedShape.WriteTNamingNode("0:1:1", "01_Selected", true);
    FusedShape.WriteTNamingNode("0:2", "02_BaseBox", false);
    FusedShape.WriteTNamingNode("0:3", "03_BaseCyl", false);
    FusedShape.WriteTNamingNode("0:4", "04_FusedShape", false);

    // Fillet the selected edge
    TopoDS_Edge RecoveredEdge = FusedShape.getSelectedEdge(selectionLabel);
    BRepFilletAPI_MakeFillet mkFillet(FusedShape.getShape());
    mkFillet.Add(2., 2., RecoveredEdge);
    mkFillet.Build();

    // Record the Fillet Operation
    TopoShape FilletedShape;// = mkFillet.Shape();
    FilletedShape.setShape(FusedShape, mkFillet);

    // write out the latest node
    FusedShape.WriteTNamingNode("0:5", "05_FilletedShape", false);
    
    //--------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------
    //                  FUSE DONE, ABOUT TO RESIZE THE CYLINDER
    //--------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------

    // resize the cylinder. I believe FreeCAD just creates a whole new cylinder
    TopoDS_Shape Cylinder2 = BRepPrimAPI_MakeCylinder(2., 15.);
    TopoShape NewCylShape;
    NewCylShape.setShape(Cylinder2);

    // Now the FreeCAD algorithms figure out that Fuse and Fillet need to be re-run
    // First, re-do Fuse
    TopoShape ReFusedShape;
    BRepAlgoAPI_Fuse mkFuse2(BoxShape.getShape(), NewCylShape.getShape());
    ReFusedShape.setShape(BoxShape, mkFuse2);

    BRepFilletAPI_MakeFillet mkFillet2(ReFusedShape.getShape());
    // grab the selected edge from our tree to re-fillet
    TopoDS_Edge RecoveredEdge2 = ReFusedShape.getSelectedEdge(selectionLabel);

    // now re-do fillet
    mkFillet2.Add(2., 2., RecoveredEdge);
    mkFillet2.Build();

    // Record the Fillet Operation
    TopoShape ReFilletedShape;// = mkFillet2.Shape();
    ReFilletedShape.setShape(ReFusedShape, mkFillet2);

    // Write out some more shapes
    FusedShape.WriteTNamingNode("0:6", "06_PartOfFusionMaybe", false);
    FusedShape.WriteTNamingNode("0:7", "07_ReFusion", false);
    FusedShape.WriteTNamingNode("0:8", "08_ReFillet", false);

    return FusedShape;
}
TopoShape SimpleBoxWithNaming(){
    // We'll do this like freecad, first create TopoDS_Shape
    const TopoDS_Shape& Box = BRepPrimAPI_MakeBox(10., 10., 10.);
    // create Base Shape that gets passed to FilletFeature
    TopoShape BaseShape(Box);
    //std::clog << "Dumping deep TDF tree\n";
    //std::clog << BaseShape.DeepDeepDumpTopoHistory();

    // create blank TopoShape in FilletFeature and add Base Shape
    TopoShape BoxShape;
    BoxShape.addShape(Box);

    // Finaly, 'Select' the edge
    std::cout << "Trying to select the first time" << std::endl;
    std::string selectionLabel = BoxShape.selectEdge(3);
    //std::cout << "Trying to select a second time" << std::endl;
    //std::string selectionLabel2 = BoxShape.selectEdge(3);
    //std::clog << "Dumping tree" << std::endl;
    //std::clog << BoxShape.DumpTopoHistory();
    //std::clog << "|____________________|" << std::endl;
    
    // And fillet the box
    std::clog << "Running makeTopoShape" << std::endl;
    BoxShape.makeTopoShapeFillet(2., 2., selectionLabel);

    //std::clog << "-------------------------" << std::endl;
    std::clog << "------------ REBUILDING ----------" << std::endl;
    //std::clog << "-------------------------" << std::endl;

    // make box taller
    const TopoDS_Shape& Box2 = BRepPrimAPI_MakeBox(10., 20., 20.);
    BoxShape.modifyShape("0:2", Box2);
    std::clog << BoxShape.DumpTopoHistory();


    // try re-building the box
    TopoDS_Edge recoveredEdge = TopoDS::Edge(BoxShape.getSelectedEdge(selectionLabel));
    //TopoDS_Shape recoveredBase = BoxShape.getSelectedBaseShape(selectionLabel);
    //TopoDS_Shape recoveredBase = BoxShape.getNodeShape("0:4");
    TopoDS_Shape recoveredBase = BoxShape.getTipShape();

    //if (recoveredBase.IsNull()){
        //std::cout << "BaseShape is NULL....\n";
    //}
    //else{
        //std::cout << "BaseShape is not NULL!!!!\n";
    //}

    //if (recoveredEdge.IsNull()){
        //std::cout << "recoveredEdge is Nul..." << std::endl;
    //}
    //else{
        //std::cout << "recoveredEdge is NOT NULL!!!!" << std::endl;
    //}

    TopTools_IndexedMapOfShape edges;
    TopExp::MapShapes(recoveredBase, TopAbs_EDGE, edges);
    if (edges.Contains(recoveredEdge)){
        std::cout << "Yes the Edge is in the box...\n";
    }
    else{
        std::cout << "No, the Edge is not in the Box...\n";
    }

    //BoxShape.makeTopoShapeFillet(2., 2., selectionLabel);

    return BoxShape;
}
int main() {

	// The IfcHierarchyHelper is a subclass of the regular IfcFile that provides several
	// convenience functions for working with geometry in IFC files.
	IfcHierarchyHelper file;
	file.header().file_name().name("IfcAdvancedHouse.ifc");

	IfcSchema::IfcBuilding* building = file.addBuilding();
	// By adding a building, a hierarchy has been automatically created that consists of the following
	// structure: IfcProject > IfcSite > IfcBuilding

	// Lateron changing the name of the IfcProject can be done by obtaining a reference to the 
	// project, which has been created automatically.
	file.getSingle<IfcSchema::IfcProject>()->setName("IfcOpenHouse");

	// To demonstrate the ability to serialize arbitrary opencascade solids a building envelope is
	// constructed by applying boolean operations. Naturally, in IFC, building elements should be 
	// modeled separately, with rich parametric and relational semantics. Creating geometry in this
	// way does not preserve any history and is merely a demonstration of technical capabilities.
	TopoDS_Shape outer =   BRepPrimAPI_MakeBox(gp_Pnt(-5000., -180., -2000.), gp_Pnt(5000., 5180., 3000.)).Shape();
	TopoDS_Shape inner =   BRepPrimAPI_MakeBox(gp_Pnt(-4640.,  180.,     0.), gp_Pnt(4640., 4820., 3000.)).Shape();
	TopoDS_Shape window1 = BRepPrimAPI_MakeBox(gp_Pnt(-5000., -180.,   400.), gp_Pnt( 500., 1180., 2000.)).Shape();
	TopoDS_Shape window2 = BRepPrimAPI_MakeBox(gp_Pnt( 2070., -180.,   400.), gp_Pnt(3930.,  180., 2000.)).Shape();

	TopoDS_Shape building_shell = BRepAlgoAPI_Cut(
		BRepAlgoAPI_Cut(
			BRepAlgoAPI_Cut(outer, inner),
			window1
			),
		window2
	);

	// Since the solid consists only of planar faces and straight edges it can be serialized as an
	// IfcFacetedBRep. If it would not be a polyhedron, serialise() can only be successful when linked
	// to the IFC4 model and with `advanced` set to `true` which introduces IfcAdvancedFace. It would
	// return `0` otherwise.
	IfcSchema::IfcProductDefinitionShape* building_shape = IfcGeom::serialise(building_shell, false);
	
	file.addEntity(building_shape);
	IfcSchema::IfcRepresentation* rep = *building_shape->Representations()->begin();
	rep->setContextOfItems(file.getRepresentationContext("model"));

	building->setRepresentation(building_shape);

	// A pale white colour is assigned to the building.
	file.setSurfaceColour(
		building_shape, 0.75, 0.73, 0.68);

	// For the ground mesh of the IfcSite we will use a Nurbs surface created in Open Cascade. Only
	// in IFC4 the surface can be directly serialized. In IFC2X3 the it will have to be tesselated.
	TopoDS_Shape shape;
	createGroundShape(shape);

	IfcSchema::IfcProductDefinitionShape* ground_representation = IfcGeom::serialise(shape, true);
	if (!ground_representation) {
		ground_representation = IfcGeom::tesselate(shape, 100.);
	}
	file.getSingle<IfcSchema::IfcSite>()->setRepresentation(ground_representation);
	
	IfcSchema::IfcRepresentation::list::ptr ground_reps = file.getSingle<IfcSchema::IfcSite>()->Representation()->Representations();
	for (IfcSchema::IfcRepresentation::list::it it = ground_reps->begin(); it != ground_reps->end(); ++it) {
		(*it)->setContextOfItems(file.getRepresentationContext("Model"));
	}
	file.addEntity(ground_representation);
	file.setSurfaceColour(ground_representation, 0.15, 0.25, 0.05);

    /*
    // Note that IFC lacks elementary surfaces that STEP does have, such as spherical_surface.
    // BRepBuilderAPI_NurbsConvert can be used to serialize such surfaces as nurbs surfaces.
	TopoDS_Shape sphere = BRepPrimAPI_MakeSphere(gp_Pnt(), 1000.).Shape();
	IfcSchema::IfcProductDefinitionShape* sphere_representation = IfcGeom::serialise(sphere, true);
	if (S(IfcSchema::Identifier) == "IFC4") {
		sphere = BRepBuilderAPI_NurbsConvert(sphere, true).Shape();
		sphere_representation = IfcGeom::serialise(sphere, true);
	}
    */

	// Finally create a file stream for our output and write the IFC file to it.
	std::ofstream f("IfcAdvancedHouse.ifc");
	f << file;
}
예제 #14
0
CCuboid::CCuboid(const gp_Ax2& pos, double x, double y, double z, const wxChar* title, const HeeksColor& col, float opacity)
:CSolid(BRepPrimAPI_MakeBox(gp_Ax2(pos.Location().XYZ() + gp_XYZ((x < 0) ? x:0.0, (y < 0) ? y:0.0, (z < 0) ? z:0.0), pos.Direction(), pos.XDirection()), fabs(x), fabs(y), fabs(z)), title, col, opacity)
, m_pos(pos), m_x(x), m_y(y), m_z(z)
{
}