Exemple #1
0
bool CSketch::FilletAtPoint(const gp_Pnt& p, double rad)
{
	std::list<TopoDS_Shape> faces;
	bool fillet_done = false;

	if(ConvertSketchToFaceOrWire(this, faces, true))
	{
		for(std::list<TopoDS_Shape>::iterator It2 = faces.begin(); It2 != faces.end(); It2++)
		{
			TopoDS_Shape& shape = *It2;
			if(shape.ShapeType() != TopAbs_FACE)continue;
			const TopoDS_Face& face = TopoDS::Face(shape);
			BRepFilletAPI_MakeFillet2d fillet(face);
			TopoDS_Vertex Vertex;
			if(!FindClosestVertex(p, face, Vertex))continue;
			fillet.AddFillet(Vertex, rad);
			if(fillet.Status() != ChFi2d_IsDone)continue;
			const TopoDS_Shape& new_shape = fillet.Shape();
			if(new_shape.ShapeType() != TopAbs_FACE)continue;
			const TopoDS_Face& new_face = TopoDS::Face(new_shape);
			HeeksObj* new_object = new CSketch();
			if(ConvertFaceToSketch2(new_face, new_object, FaceToSketchTool::deviation))
			{
				*this = *((CSketch*)new_object);
				delete new_object;
				fillet_done = true;
			}
		}
	}

	return fillet_done;
}
Exemple #2
0
void ConvertToFaceOrWire(std::list<HeeksObj*> list, std::list<TopoDS_Shape> &faces_or_wires, bool face_not_wire)
{
	std::list<HeeksObj*> sketches_or_faces_to_delete;

	for(std::list<HeeksObj *>::const_iterator It = list.begin(); It != list.end(); It++)
	{
		HeeksObj* object = *It;
		switch(object->GetType())
		{
		case SketchType:
		case CircleType:
			{
				if(ConvertSketchToFaceOrWire(object, faces_or_wires, face_not_wire))
				{
					if(wxGetApp().m_extrude_removes_sketches)sketches_or_faces_to_delete.push_back(object);
				}
			}
			break;

		case FaceType:
			faces_or_wires.push_back(((CFace*)object)->Face());
			if(wxGetApp().m_extrude_removes_sketches)sketches_or_faces_to_delete.push_back(object);
			break;

		default:
			break;
		}
	}

	wxGetApp().DeleteUndoably(sketches_or_faces_to_delete);
}
Exemple #3
0
HeeksObj *CSketch::Parallel( const double distance )
{
    try {
            double deviation = heekscad_interface.GetTolerance();
            std::list<TopoDS_Shape> wires;
            if(ConvertSketchToFaceOrWire(this, wires, false))
            {
                HeeksObj *sketch = heekscad_interface.NewSketch();
                for(std::list<TopoDS_Shape>::iterator It2 = wires.begin(); It2 != wires.end(); It2++)
                {
                    TopoDS_Shape& wire = *It2;
                    BRepOffsetAPI_MakeOffset offset_wire(TopoDS::Wire(wire));
                    offset_wire.Perform(distance);
                    ConvertWireToSketch(TopoDS::Wire(offset_wire.Shape()), sketch, deviation);
                }
                return(sketch);
            }
        }
		catch (Standard_Failure) {
			Handle_Standard_Failure e = Standard_Failure::Caught();
			// wxMessageBox(wxString(_("Error making offset")) + _T(": ") + Ctt(e->GetMessageString()));
			return(NULL);
		}

		return(NULL);
}
Exemple #4
0
HeeksObj* CreatePipeFromProfile(HeeksObj* spine, HeeksObj* profile)
{
	const TopoDS_Wire wire = ((CWire*)spine)->Wire();
	std::list<TopoDS_Shape> faces;
	if(!ConvertSketchToFaceOrWire(profile, faces, true))return NULL;
	HeeksObj* pipe = CreatePipeFromProfile(wire, faces);
	if(pipe)
	{
		wxGetApp().DeleteUndoably(profile);
	}
	return pipe;
}
Exemple #5
0
	void Run()
	{
		std::list<TopoDS_Shape> wires;
		if(ConvertSketchToFaceOrWire(sketch_for_tools, wires, false))
		{
			wxGetApp().CreateUndoPoint();
			for(std::list<TopoDS_Shape>::iterator It2 = wires.begin(); It2 != wires.end(); It2++)
			{
				TopoDS_Shape& wire = *It2;
				wxGetApp().Add(new CWire(TopoDS::Wire(wire), _T("Wire from sketch")), NULL);
			}
			wxGetApp().Changed();
		}
	}
Exemple #6
0
	void Run()
	{
		std::list<TopoDS_Shape> faces;
		if(ConvertSketchToFaceOrWire(sketch_for_tools, faces, true))
		{
			wxGetApp().CreateUndoPoint();
			for(std::list<TopoDS_Shape>::iterator It2 = faces.begin(); It2 != faces.end(); It2++)
			{
				TopoDS_Shape& face = *It2;
				wxGetApp().Add(new CFace(TopoDS::Face(face)), NULL);
			}
			wxGetApp().Changed();
		}
	}
Exemple #7
0
	void Run()
	{
		std::list<TopoDS_Shape> wires;
		if(ConvertSketchToFaceOrWire(sketch_for_tools, wires, false))
		{
			wxGetApp().StartHistory();
			for(std::list<TopoDS_Shape>::iterator It2 = wires.begin(); It2 != wires.end(); It2++)
			{
				TopoDS_Shape& wire = *It2;
				wxGetApp().AddUndoably(new CWire(TopoDS::Wire(wire), _T("Wire from sketch")), NULL, NULL);
			}
			wxGetApp().EndHistory();
		}
	}
Exemple #8
0
	void Run()
	{
		std::list<TopoDS_Shape> faces;
		if(ConvertSketchToFaceOrWire(sketch_for_tools, faces, true))
		{
			wxGetApp().StartHistory();
			for(std::list<TopoDS_Shape>::iterator It2 = faces.begin(); It2 != faces.end(); It2++)
			{
				TopoDS_Shape& face = *It2;
				wxGetApp().AddUndoably(new CFace(TopoDS::Face(face)), NULL, NULL);
			}
			wxGetApp().EndHistory();
		}
	}
Exemple #9
0
	void Run()
	{
		std::list<HeeksObj*>::const_iterator It;
		for(It = wxGetApp().m_marked_list->list().begin(); It != wxGetApp().m_marked_list->list().end(); It++)
		{
			HeeksObj* obj = (HeeksObj*)*It;
			if(obj->GetType() == SketchType)
			{
				CSketch* sketch = (CSketch*)obj;

                std::list<TopoDS_Shape> wires;
                if (! ConvertSketchToFaceOrWire( sketch, wires, false))
                {
                    wxMessageBox(_("Failed to convert sketch to wire"));
                } // End if - then
                else
                {
                    try {
                        // For all wires in this sketch...
                        for(std::list<TopoDS_Shape>::iterator It2 = wires.begin(); It2 != wires.end(); It2++)
                        {
                            TopoDS_Shape& wire_to_fix = *It2;
                            ShapeFix_Wire fix;
                            fix.Load( TopoDS::Wire(wire_to_fix) );
                            // fix.ClearModes();

                            fix.ModifyTopologyMode() = sketch_tool_options.m_modify_topology;
                            fix.ModifyGeometryMode() = sketch_tool_options.m_modify_geometry;
                            fix.ClosedWireMode() = sketch_tool_options.m_closed_wire;
                            fix.PreferencePCurveMode() = sketch_tool_options.m_preference_pcurve;
                            fix.FixGapsByRangesMode() = sketch_tool_options.m_fix_gaps_by_ranges;
                            fix.FixSelfIntersectionMode() = sketch_tool_options.m_fix_self_intersection;
                            fix.FixReorderMode() = sketch_tool_options.m_reorder;
                            fix.FixDegeneratedMode() = sketch_tool_options.m_fix_degenerated;

                            if (sketch_tool_options.m_fix_small)
                            {
                                fix.FixSmallMode() = true;
                                fix.FixSmall( false, sketch_tool_options.m_fix_small_precision );
                            }

                            if (sketch_tool_options.m_fix_lacking)
                            {
                                fix.FixLackingMode() = sketch_tool_options.m_fix_lacking;
                                fix.FixLacking(false);
                            }

                            if (! fix.Perform())
                            {
                                wxMessageBox(_("Wire fix failed"));
                            }
                            else
                            {
                                TopoDS_Shape wire = fix.Wire();
                                HeeksObj *new_sketch = heekscad_interface.NewSketch();
                                double deviation = 0.001;
                                if (!  ConvertWireToSketch(TopoDS::Wire(wire), new_sketch, deviation))
                                {
                                    wxMessageBox(_("Failed to convert wire to sketch"));
                                }
                                else
                                {
                                    if (sketch != NULL)
                                    {
                                        heekscad_interface.Remove( sketch );
                                        sketch = NULL;
                                    }

                                    heekscad_interface.Add(new_sketch, NULL);
                                }
                            }
                        }
                    } // End try
                    catch (Standard_Failure & error) {
                        (void) error;	// Avoid the compiler warning.
                        Handle_Standard_Failure e = Standard_Failure::Caught();
                        wxMessageBox(_("Failed to fix wire"));
                    } // End catch
                }
			}
		}
	}