HeeksObj* CreateRuledFromSketches(std::list<HeeksObj*> list, bool make_solid) { std::list<TopoDS_Wire> wire_list; for(std::list<HeeksObj *>::iterator It = list.begin(); It != list.end(); It++) { HeeksObj* object = *It; if(object->GetType() == SketchType) { std::list<HeeksObj*> s; s.push_back(object); TopoDS_Wire wire; if(ConvertLineArcsToWire2(s, wire)) { wire_list.push_back(wire); } } } TopoDS_Shape shape; if(CreateRuledSurface(wire_list, shape, make_solid)) { return CShape::MakeObject(shape, _("Ruled Surface"), SOLID_TYPE_UNKNOWN, HeeksColor(51, 45, 51), 1.0f); } return NULL; }
void HGear::glCommands(bool select, bool marked, bool no_color){ if(!no_color){ wxGetApp().glColorEnsuringContrast(HeeksColor(0, 0, 0)); } GLfloat save_depth_range[2]; if(marked){ glGetFloatv(GL_DEPTH_RANGE, save_depth_range); glDepthRange(0, 0); glLineWidth(2); } height_for_point = 0.0; glBegin(GL_LINE_STRIP); GetSegments(glVertexFunction, wxGetApp().GetPixelScale()); glEnd(); if(fabs(m_depth) > 0.000000000001) { height_for_point = m_depth; glBegin(GL_LINE_STRIP); GetSegments(glVertexFunction, wxGetApp().GetPixelScale()); glEnd(); } if(marked){ glLineWidth(1); glDepthRange(save_depth_range[0], save_depth_range[1]); } }
void CMeshVertex::MakeSureDisplayListExists() { if(m_gl_list)return; m_gl_list = glGenLists(1); glNewList(m_gl_list, GL_COMPILE); HeeksColor(255, 0, 128).glColor(); glRasterPos3dv(vertex().GetPtr()); glEndList(); }
// static member function HeeksObj* HLine::ReadFromXMLElement(TiXmlElement* pElem) { gp_Pnt p0(0, 0, 0), p1(0, 0, 0); HeeksColor c; // get the attributes for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next()) { std::string name(a->Name()); if(name == "col"){c = HeeksColor((long)(a->IntValue()));} else if(name == "sx"){p0.SetX(a->DoubleValue());} else if(name == "sy"){p0.SetY(a->DoubleValue());} else if(name == "sz"){p0.SetZ(a->DoubleValue());} else if(name == "ex"){p1.SetX(a->DoubleValue());} else if(name == "ey"){p1.SetY(a->DoubleValue());} else if(name == "ez"){p1.SetZ(a->DoubleValue());} } HLine* new_object = new HLine(p0, p1, &c); new_object->ReadBaseXML(pElem); if(new_object->GetNumChildren()>2) { //This is a new style line, with children points new_object->Remove(new_object->A); new_object->Remove(new_object->B); delete new_object->A; delete new_object->B; new_object->A = (HPoint*)new_object->GetFirstChild(); new_object->B = (HPoint*)new_object->GetNextChild(); new_object->A->m_draw_unselected = false; new_object->B->m_draw_unselected = false; new_object->A->SetSkipForUndo(true); new_object->B->SetSkipForUndo(true); } // The OpenCascade libraries throw an exception when one tries to // create a gp_Lin() object using a vector that doesn't point // anywhere. If this is a zero-length line then we're in // trouble. Don't bother with it. if (new_object->A == NULL || new_object->B == NULL || ((new_object->A->m_p.X() == new_object->B->m_p.X()) && (new_object->A->m_p.Y() == new_object->B->m_p.Y()) && (new_object->A->m_p.Z() == new_object->B->m_p.Z()))) { delete new_object; return(NULL); } return new_object; }
void CMeshVertex::DrawGripperSelectItems() { if(heeksCAD->GetBackgroundColor() == HeeksColor(0, 0, 0))glColor3ub(255, 255, 255); else glColor3ub(0, 0, 0); Point p0 = vertex(); glBegin(GL_LINES); for(std::set<CMeshEdge*>::iterator It = m_edges.begin(); It != m_edges.end(); It++) { CMeshEdge* edge = *It; CMeshPosition& p = edge->GetControlPointNearVertex(this); Point p1 = p.vertex(); glVertex3d(p0.x, p0.y, p0.z); glVertex3d(p1.x, p1.y, p1.z); } glEnd(); }
void HeeksDxfRead::OnReadDimension(int dimension_type, double angle, double angle2, double angle3, double radius_leader_length, const double *def_point, const double *mid, const double *p1, const double *p2, const double *p3, const double *p4, const double *p5) { int type = (dimension_type & 0x07); gp_Pnt d = make_point(def_point); gp_Pnt m = make_point(mid); gp_Vec d_to_m = make_vector(d, m); gp_Pnt e = gp_Pnt(m.XYZ() + d_to_m.XYZ()); gp_Dir forward(1,0,0); HeeksColor c(0, 0, 0); if(type == 0) { forward.Rotate(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), (angle/* + angle2 + angle3*/) * -0.01745329251); } else { forward = gp_Dir(-d_to_m); c = HeeksColor(255, 0, 0); } gp_Dir left(-forward.Y(), forward.X(), 0.0); double arrow_size = 5.0; gp_Pnt da1 = d.XYZ() + forward.XYZ() * (-arrow_size) + left.XYZ() * (arrow_size * 0.25); gp_Pnt da2 = d.XYZ() + forward.XYZ() * (-arrow_size) + left.XYZ() * (arrow_size * -0.25); gp_Pnt ea1 = e.XYZ() + forward.XYZ() * (arrow_size) + left.XYZ() * (arrow_size * 0.25); gp_Pnt ea2 = e.XYZ() + forward.XYZ() * (arrow_size) + left.XYZ() * (arrow_size * -0.25); AddObject(new HLine(d, da1, &c)); AddObject(new HLine(da1, da2, &c)); AddObject(new HLine(da2, d, &c)); AddObject(new HLine(e, ea1, &c)); AddObject(new HLine(ea1, ea2, &c)); AddObject(new HLine(ea2, e, &c)); }
//static HeeksObj* HPoint::ReadFromXMLElement(TiXmlElement* pElem) { gp_Pnt p; HeeksColor c; // get the attributes for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next()) { std::string name(a->Name()); if(name == "col"){c = HeeksColor((long)(a->IntValue()));} else if(name == "x"){p.SetX(a->DoubleValue());} else if(name == "y"){p.SetY(a->DoubleValue());} else if(name == "z"){p.SetZ(a->DoubleValue());} } HPoint* new_object = new HPoint(p, &c); new_object->ReadBaseXML(pElem); return new_object; }
void Gripper::glCommands(bool select, bool marked, bool no_color){ if(!no_color){ wxGetApp().glColorEnsuringContrast(HeeksColor(0, 0, 0)); } if(wxGetApp().m_dragging_moves_objects) { if(select) { double s = 5.0 / wxGetApp().GetPixelScale(); double p[8][3] = { {-s, -s, -s}, {s, -s, -s}, {s, s, -s}, {-s, s, -s}, {-s, -s, s}, {s, -s, s}, {s, s, s}, {-s, s, s} }; for(int i = 0; i<8; i++){ p[i][0] += m_data.m_x; p[i][1] += m_data.m_y; p[i][2] += m_data.m_z; } glBegin(GL_TRIANGLES); glVertex3dv(p[0]); glVertex3dv(p[2]); glVertex3dv(p[1]); glVertex3dv(p[0]); glVertex3dv(p[3]); glVertex3dv(p[2]); glVertex3dv(p[0]); glVertex3dv(p[1]); glVertex3dv(p[5]); glVertex3dv(p[0]); glVertex3dv(p[5]); glVertex3dv(p[4]); glVertex3dv(p[3]); glVertex3dv(p[0]); glVertex3dv(p[4]); glVertex3dv(p[3]); glVertex3dv(p[4]); glVertex3dv(p[7]); glVertex3dv(p[4]); glVertex3dv(p[5]); glVertex3dv(p[6]); glVertex3dv(p[4]); glVertex3dv(p[6]); glVertex3dv(p[7]); glVertex3dv(p[3]); glVertex3dv(p[7]); glVertex3dv(p[6]); glVertex3dv(p[3]); glVertex3dv(p[6]); glVertex3dv(p[2]); glVertex3dv(p[2]); glVertex3dv(p[6]); glVertex3dv(p[5]); glVertex3dv(p[2]); glVertex3dv(p[5]); glVertex3dv(p[1]); glEnd(); } else { glRasterPos3d(m_data.m_x, m_data.m_y, m_data.m_z); switch(m_data.m_type){ case GripperTypeTranslate: glBitmap(16, 15, 8, 7, 10.0, 0.0, translation_circle); break; case GripperTypeRotateObject: glBitmap(16, 13, 8, 4, 10.0, 0.0, rotation_object_circle); break; case GripperTypeRotateObjectXY: glBitmap(16, 13, 8, 4, 10.0, 0.0, rotation_object_circle); break; case GripperTypeRotateObjectXZ: glBitmap(16, 13, 8, 4, 10.0, 0.0, rotation_object_circle); break; case GripperTypeRotateObjectYZ: glBitmap(16, 13, 8, 4, 10.0, 0.0, rotation_object_circle); break; case GripperTypeRotate: glBitmap(16, 13, 8, 4, 10.0, 0.0, rotation_circle); break; case GripperTypeScale: glBitmap(16, 15, 8, 7, 10.0, 0.0, scale_circle); break; case GripperTypeAngle: glBitmap(14, 16, 9, 11, 10.0, 0.0, angle_circle); break; case GripperTypeStretch: switch(m_data.m_alternative_icon) { case 1: glBitmap(9, 9, 4, 4, 10.0, 0.0, square); break; case 2: glBitmap(9, 9, 4, 4, 10.0, 0.0, cross); break; case 3: glBitmap(9, 9, 4, 4, 10.0, 0.0, flower); break; default: glBitmap(9, 9, 4, 4, 10.0, 0.0, circle); break; } break; default: glBitmap(9, 9, 4, 4, 10.0, 0.0, circle); break; } } } else { glRasterPos3d(m_data.m_x, m_data.m_y, m_data.m_z); glBitmap(9, 9, 4, 4, 10.0, 0.0, circle); } }
void CEdge::glCommands(bool select, bool marked, bool no_color){ if(!no_color){ wxGetApp().glColorEnsuringContrast(HeeksColor(0, 0, 0)); } if(m_owner && m_owner->m_owner && m_owner->m_owner->GetType() == SolidType) { // triangulate a face on the edge first if(this->m_faces.size() > 0) { TopLoc_Location fL; Handle_Poly_Triangulation facing = BRep_Tool::Triangulation(m_faces.front()->Face(),fL); if(!facing.IsNull()) { // Get polygon Handle_Poly_PolygonOnTriangulation polygon = BRep_Tool::PolygonOnTriangulation(m_topods_edge, facing, fL); gp_Trsf tr = fL; double m[16]; extract_transposed(tr, m); glPushMatrix(); glMultMatrixd(m); if (!polygon.IsNull()) { glBegin(GL_LINE_STRIP); const TColStd_Array1OfInteger& Nodes = polygon->Nodes(); const TColgp_Array1OfPnt& FNodes = facing->Nodes(); int nnn = polygon->NbNodes(); for (int nn = 1; nn <= nnn; nn++) { gp_Pnt v = FNodes(Nodes(nn)); glVertex3d(v.X(), v.Y(), v.Z()); } glEnd(); } glPopMatrix(); } } } else { bool glwidth_done = false; GLfloat save_depth_range[2]; if(m_owner == NULL || m_owner->m_owner == NULL || m_owner->m_owner->GetType() != WireType) { BRepTools::Clean(m_topods_edge); double pixels_per_mm = wxGetApp().GetPixelScale(); BRepMesh_IncrementalMesh(m_topods_edge, 1/pixels_per_mm); if(marked){ glGetFloatv(GL_DEPTH_RANGE, save_depth_range); glDepthRange(0, 0); glLineWidth(2); glwidth_done = true; } } TopLoc_Location L; Handle(Poly_Polygon3D) Polyg = BRep_Tool::Polygon3D(m_topods_edge, L); if (!Polyg.IsNull()) { const TColgp_Array1OfPnt& Points = Polyg->Nodes(); Standard_Integer po; glBegin(GL_LINE_STRIP); for (po = Points.Lower(); po <= Points.Upper(); po++) { gp_Pnt p = (Points.Value(po)).Transformed(L); glVertex3d(p.X(), p.Y(), p.Z()); } glEnd(); } if(glwidth_done) { glLineWidth(1); glDepthRange(save_depth_range[0], save_depth_range[1]); } } }
void PickCreateRuledSurface() { if(wxGetApp().m_marked_list->size() == 0) { wxGetApp().PickObjects(_("pick some sketches")); } if(wxGetApp().m_marked_list->size() > 0) { std::list<TopoDS_Wire> wire_list; std::list<HeeksObj*> sketches_to_delete; for(std::list<HeeksObj *>::const_iterator It = wxGetApp().m_marked_list->list().begin(); It != wxGetApp().m_marked_list->list().end(); It++) { HeeksObj* object = *It; if(object->GetType() == SketchType) { std::list<HeeksObj*> list; list.push_back(object); TopoDS_Wire wire; if(ConvertLineArcsToWire2(list, wire)) { wire_list.push_back(wire); if(wxGetApp().m_loft_removes_sketches)sketches_to_delete.push_back(object); } } } TopoDS_Shape shape; if(CreateRuledSurface(wire_list, shape, true)) { wxGetApp().StartHistory(); wxGetApp().DeleteUndoably(sketches_to_delete); HeeksObj* new_object = CShape::MakeObject(shape, _("Ruled Surface"), SOLID_TYPE_UNKNOWN, HeeksColor(51, 45, 51), 1.0f); wxGetApp().AddUndoably(new_object, NULL, NULL); wxGetApp().EndHistory(); } } }
void Run(){ gp_Vec v(line_for_tool->A->m_p, line_for_tool->B->m_p); CCone* new_object = new CCone(gp_Ax2(line_for_tool->A->m_p, v), 2.0, 1.0, v.Magnitude(), _("Cone"), HeeksColor(240, 240, 191), 1.0f); wxGetApp().CreateUndoPoint(); wxGetApp().Add(new_object,NULL); wxGetApp().Changed(); }
bool CShape::ImportSolidsFile(const wxChar* filepath, std::map<int, CShapeData> *index_map, HeeksObj* paste_into) { // only allow paste of solids at top level or to groups if(paste_into && paste_into->GetType() != GroupType)return false; // returns true, if suffix handled wxString wf(filepath); HeeksObj* add_to = &wxGetApp(); if(paste_into)add_to = paste_into; if(wf.EndsWith(_T(".stp")) || wf.EndsWith(_T(".STP")) || wf.EndsWith(_T(".step")) || wf.EndsWith(_T(".STEP"))) { char oldlocale[1000]; strcpy(oldlocale, setlocale(LC_NUMERIC, "C")); Standard_CString aFileName = (Standard_CString) (Ttc(filepath)); STEPControl_Reader Reader; int status = Reader.ReadFile( aFileName ); if ( status == IFSelect_RetDone ) { int num = Reader.NbRootsForTransfer(); for(int i = 1; i<=num; i++) { Handle_Standard_Transient root = Reader.RootForTransfer(i); Reader.TransferEntity(root); TopoDS_Shape rShape = Reader.Shape(i); if(index_map) { // change the id ( and any other data ), to the one in the step file index std::map<int, CShapeData>::iterator FindIt = index_map->find(i); if(FindIt != index_map->end()) { CShapeData& shape_data = FindIt->second; HeeksObj* new_object = MakeObject(rShape, _("STEP solid"), shape_data.m_solid_type, HeeksColor(191, 191, 191), 1.0f); if(new_object) { add_to->Add(new_object, NULL); shape_data.SetShape((CShape*)new_object); } } } else { HeeksObj* new_object = MakeObject(rShape, _("STEP solid"), SOLID_TYPE_UNKNOWN, HeeksColor(191, 191, 191), 1.0f); add_to->Add(new_object, NULL); } } } else{ wxMessageBox(_("STEP import not done!")); } setlocale(LC_NUMERIC, oldlocale); return true; } else if(wf.EndsWith(_T(".igs")) || wf.EndsWith(_T(".IGS")) || wf.EndsWith(_T(".iges")) || wf.EndsWith(_T(".IGES"))) { char oldlocale[1000]; strcpy(oldlocale, setlocale(LC_NUMERIC, "C")); Standard_CString aFileName = (Standard_CString) (Ttc(filepath)); // //#ifdef WIN32 //#ifdef UNICODE // // if the const char* filename is different to the original unicode filename, then copy the file to a temporary file with a simple name // if(stricmp(Ctt(aFileName), filepath)) // { // wxStandardPaths standard_paths; // wxFileName path( standard_paths.GetTempDir().c_str(), _("temp_iges.igs")); // copy_file; // to do // m_backup_file_name = path.GetFullPath(); //#endif //#endif IGESControl_Reader Reader; int status = Reader.ReadFile( aFileName ); if ( status == IFSelect_RetDone ) { Reader.TransferRoots(); TopoDS_Shape shape = Reader.OneShape(); HeeksObj* new_object = MakeObject(shape, _("IGES shape"), SOLID_TYPE_UNKNOWN, HeeksColor(191, 191, 191), 1.0f); add_to->Add(new_object, NULL); #if 0 Reader.TransferRoots(); int num_shapes = Reader.NbShapes(); if(num_shapes > 0) { BRepOffsetAPI_Sewing face_sewing (0.001); int shapes_added_for_sewing = 0; for(int j = 1; j<= num_shapes; j++) { TopoDS_Shape rShape = Reader.Shape(j); if(rShape.ShapeType() == TopAbs_EDGE) { HeeksObj* new_object = new CEdge(TopoDS::Edge(rShape)); add_to->Add(new_object, NULL); } else { face_sewing.Add (rShape); shapes_added_for_sewing++; } } if(shapes_added_for_sewing > 0) { face_sewing.Perform (); if(!face_sewing.SewedShape().IsNull()) { HeeksObj* new_object = MakeObject(face_sewing.SewedShape(), _("sewed IGES solid"), SOLID_TYPE_UNKNOWN, HeeksColor(191, 191, 191)); add_to->Add(new_object, NULL); } } } #endif } else{ wxMessageBox(_("IGES import not done!")); } setlocale(LC_NUMERIC, oldlocale); return true; } else if(wf.EndsWith(_T(".brep")) || wf.EndsWith(_T(".BREP"))) { char oldlocale[1000]; strcpy(oldlocale, setlocale(LC_NUMERIC, "C")); TopoDS_Shape shape; BRep_Builder builder; Standard_Boolean result = BRepTools::Read( shape,(char *) Ttc(filepath), builder ); if(result) { HeeksObj* new_object = MakeObject(shape, _("BREP solid"), SOLID_TYPE_UNKNOWN, HeeksColor(191, 191, 191), 1.0f); add_to->Add(new_object, NULL); } else{ wxMessageBox(_("STEP import not done!")); } setlocale(LC_NUMERIC, oldlocale); return true; } return false; }
// static HeeksObj* HDimension::ReadFromXMLElement(TiXmlElement* pElem) { double m[16]; wxString text; HeeksColor c; double p0[3] = {0, 0, 0}; double p1[3] = {0, 0, 0}; double p2[3] = {0, 0, 0}; double scale=1; DimensionMode mode = TwoPointsDimensionMode; DimensionUnits units = DimensionUnitsGlobal; // get the attributes for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next()) { std::string name(a->Name()); if(name == "col"){c = HeeksColor((long)(a->IntValue()));} else if(name == "m0"){m[0] = a->DoubleValue();} else if(name == "m1"){m[1] = a->DoubleValue();} else if(name == "m2"){m[2] = a->DoubleValue();} else if(name == "m3"){m[3] = a->DoubleValue();} else if(name == "m4"){m[4] = a->DoubleValue();} else if(name == "m5"){m[5] = a->DoubleValue();} else if(name == "m6"){m[6] = a->DoubleValue();} else if(name == "m7"){m[7] = a->DoubleValue();} else if(name == "m8"){m[8] = a->DoubleValue();} else if(name == "m9"){m[9] = a->DoubleValue();} else if(name == "ma"){m[10]= a->DoubleValue();} else if(name == "mb"){m[11]= a->DoubleValue();} else if(name == "scale"){scale= a->DoubleValue();} else if(name == "mode"){mode = (DimensionMode)(a->IntValue());} else if(name == "units"){ const char* str = a->Value(); switch(str[0]) { case 'm': units = DimensionUnitsMM; break; case 'i': units = DimensionUnitsInches; break; } } } HDimension* new_object = new HDimension(make_matrix(m), make_point(p0), make_point(p1), make_point(p2), mode, units, &c); new_object->ReadBaseXML(pElem); new_object->m_scale = scale; if(new_object->GetNumChildren()>3) { //This is a new style line, with children points new_object->Remove(new_object->A); new_object->Remove(new_object->B); new_object->Remove(new_object->m_p2); delete new_object->A; delete new_object->B; delete new_object->m_p2; new_object->A = (HPoint*)new_object->GetFirstChild(); new_object->B = (HPoint*)new_object->GetNextChild(); new_object->m_p2 = (HPoint*)new_object->GetNextChild(); new_object->A->m_draw_unselected = false; new_object->B->m_draw_unselected = false; new_object->m_p2->m_draw_unselected = false; new_object->A->SetSkipForUndo(true); new_object->B->SetSkipForUndo(true); new_object->m_p2->SetSkipForUndo(true); } return new_object; }
HeeksColor *HeeksDxfRead::ActiveColorPtr(Aci_t & aci) { static HeeksColor color; color = HeeksColor(aci); return(&color); }