Modified:
/trunk/HeeksCAD installer.iss
/trunk/interface/HeeksCADInterface.cpp
/trunk/interface/HeeksCADInterface.h
/trunk/src/HGear.cpp
/trunk/src/HGear.h
/trunk/src/HeeksCAD.cpp
/trunk/src/HeeksCAD.h
/trunk/src/Sketch.cpp
/trunk/src/Sketch.h
/trunk/src/SolidTools.cpp
=======================================
--- /trunk/HeeksCAD installer.iss Thu May 12 07:04:51 2011
+++ /trunk/HeeksCAD installer.iss Mon Dec 19 22:06:04 2011
@@ -7,14 +7,14 @@
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{A8D3AD0D-D36E-4970-BE77-76A840EA2831}
AppName=HeeksCAD
-AppVerName=HeeksCAD 0.18.0
+AppVerName=HeeksCAD 0.19.0
AppPublisher=Heeks Software
AppPublisherURL=http://heeks.net/
AppSupportURL=http://code.google.com/p/heekscad/
AppUpdatesURL=http://code.google.com/p/heekscad/
DefaultDirName={pf}\HeeksCAD
DefaultGroupName=HeeksCAD
-OutputBaseFilename=HeeksCAD 0.18.0
+OutputBaseFilename=HeeksCAD 0.19.0
Compression=lzma
SolidCompression=yes
@@ -28,19 +28,19 @@
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}";
GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
-Source: "C:\Users\Dan\HeeksCAD\HeeksCAD.exe"; DestDir: "{app}"; Flags:
ignoreversion
-Source: "C:\Users\Dan\HeeksCAD\bitmaps\*.png"; DestDir: "{app}\bitmaps";
Flags: ignoreversion
-Source: "C:\Users\Dan\HeeksCAD\bitmaps\font.glf";
DestDir: "{app}\bitmaps"; Flags: ignoreversion
-Source: "C:\Users\Dan\HeeksCAD\icons\*.png"; DestDir: "{app}\icons";
Flags: ignoreversion
+Source: "C:\Users\Dan\HeeksCADSVN\HeeksCAD.exe"; DestDir: "{app}"; Flags:
ignoreversion
+Source: "C:\Users\Dan\HeeksCADSVN\bitmaps\*.png";
DestDir: "{app}\bitmaps"; Flags: ignoreversion
+Source: "C:\Users\Dan\HeeksCADSVN\bitmaps\font.glf";
DestDir: "{app}\bitmaps"; Flags: ignoreversion
+Source: "C:\Users\Dan\HeeksCADSVN\icons\*.png"; DestDir: "{app}\icons";
Flags: ignoreversion
Source: "C:\Users\Dan\OCC dlls for HeeksCAD\*"; DestDir: "{app}"; Flags:
ignoreversion
-Source: "C:\Users\Dan\HeeksCAD\de\*"; DestDir: "{app}\de"; Flags:
ignoreversion
-Source: "C:\Users\Dan\HeeksCAD\it\*"; DestDir: "{app}\it"; Flags:
ignoreversion
-Source: "C:\Users\Dan\HeeksCAD\fr\*"; DestDir: "{app}\fr"; Flags:
ignoreversion
-Source: "C:\Users\Dan\HeeksCAD\sk\*"; DestDir: "{app}\sk"; Flags:
ignoreversion
-Source: "C:\Users\Dan\HeeksCAD\wxmsw28u_gl_vc_custom.dll";
DestDir: "{app}"; Flags: ignoreversion
-Source: "C:\Users\Dan\HeeksCAD\wxmsw28u_core_vc_custom.dll";
DestDir: "{app}"; Flags: ignoreversion
-Source: "C:\Users\Dan\HeeksCAD\wxmsw28u_aui_vc_custom.dll";
DestDir: "{app}"; Flags: ignoreversion
-Source: "C:\Users\Dan\HeeksCAD\wxbase28u_vc_custom.dll"; DestDir: "{app}";
Flags: ignoreversion
+Source: "C:\Users\Dan\HeeksCADSVN\de\*"; DestDir: "{app}\de"; Flags:
ignoreversion
+Source: "C:\Users\Dan\HeeksCADSVN\it\*"; DestDir: "{app}\it"; Flags:
ignoreversion
+Source: "C:\Users\Dan\HeeksCADSVN\fr\*"; DestDir: "{app}\fr"; Flags:
ignoreversion
+Source: "C:\Users\Dan\HeeksCADSVN\sk\*"; DestDir: "{app}\sk"; Flags:
ignoreversion
+Source: "C:\Users\Dan\HeeksCADSVN\wxmsw28u_gl_vc_custom.dll";
DestDir: "{app}"; Flags: ignoreversion
+Source: "C:\Users\Dan\HeeksCADSVN\wxmsw28u_core_vc_custom.dll";
DestDir: "{app}"; Flags: ignoreversion
+Source: "C:\Users\Dan\HeeksCADSVN\wxmsw28u_aui_vc_custom.dll";
DestDir: "{app}"; Flags: ignoreversion
+Source: "C:\Users\Dan\HeeksCADSVN\wxbase28u_vc_custom.dll";
DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Program Files\Microsoft Visual Studio
9.0\VC\redist\x86\Microsoft.VC90.CRT\*"; DestDir: "{app}"; Flags:
ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
=======================================
--- /trunk/interface/HeeksCADInterface.cpp Mon Jun 20 16:12:27 2011
+++ /trunk/interface/HeeksCADInterface.cpp Mon Dec 19 22:06:04 2011
@@ -864,9 +864,9 @@
wxGetApp().m_frame->m_graphics->OnMagXYZ(recalculate_gl_lists);
}
-void CHeeksCADInterface::SaveSTLFile(const std::list<HeeksObj*>& objects,
const wxChar *filepath, double facet_tolerance, double *scale)
-{
- wxGetApp().SaveSTLFile(objects, filepath, facet_tolerance, scale);
+void CHeeksCADInterface::SaveSTLFile(const std::list<HeeksObj*>& objects,
const wxChar *filepath, double facet_tolerance, double *scale, bool binary)
+{
+ wxGetApp().SaveSTLFile(objects, filepath, facet_tolerance, scale, binary);
}
SketchOrderType CHeeksCADInterface::GetSketchOrder(HeeksObj* sketch)
@@ -1615,6 +1615,11 @@
{
((HSpline*)spline)->ToBiarcs(new_spans, tolerance);
}
+
+HeeksObj* CHeeksCADInterface::SketchSplineToBiarcs(HeeksObj* sketch,
double tolerance)
+{
+ return ((CSketch*)sketch)->SplineToBiarcs(tolerance);
+}
HeeksObj* CHeeksCADInterface::NewSplineFromPoints(unsigned int num_points,
const double* d3)
{
=======================================
--- /trunk/interface/HeeksCADInterface.h Mon Jun 20 16:12:27 2011
+++ /trunk/interface/HeeksCADInterface.h Mon Dec 19 22:06:04 2011
@@ -167,7 +167,7 @@
virtual void SetViewBox(const double* b);
virtual void ViewExtents(bool rotate);
virtual void XYZView(bool recalculate_gl_lists);
- virtual void SaveSTLFile(const std::list<HeeksObj*>& objects, const
wxChar *filepath, double facet_tolerance = -1, double* scale = NULL);
+ virtual void SaveSTLFile(const std::list<HeeksObj*>& objects, const
wxChar *filepath, double facet_tolerance = -1, double* scale = NULL, bool
binary = true);
// sketches
virtual SketchOrderType GetSketchOrder(HeeksObj* sketch);
@@ -309,6 +309,7 @@
virtual double GetViewUnits();
virtual void SetViewUnits(double units, bool write_to_config);
virtual void SplineToBiarcs(HeeksObj* spline, std::list<HeeksObj*>
&new_spans, double tolerance);
+ virtual HeeksObj* SketchSplineToBiarcs(HeeksObj* sketch, double
tolerance);
virtual HeeksObj* NewSplineFromPoints(unsigned int num_points, const
double* d3); // list of 3 doubles
// Geometry functions
=======================================
--- /trunk/src/HGear.cpp Sun Nov 13 10:27:36 2011
+++ /trunk/src/HGear.cpp Mon Dec 19 22:06:04 2011
@@ -20,16 +20,14 @@
HGear::HGear(){
m_num_teeth = 12;
m_module = 1.0;
- m_clearance = 0.8;
m_addendum_offset = 0.0;
m_addendum_multiplier = 1.0;
m_dedendum_multiplier = 1.0;
m_pressure_angle = 0.34906585039886; // 20 degrees
- m_spacing = 0.0;
m_tip_relief = 0.05;
m_depth = 0.0;
m_cone_half_angle = 0.0;
- m_inner_ring = 1.0;
+ m_angle = 0.0;
}
HGear::~HGear(){
@@ -289,46 +287,48 @@
void line_arc_line(double tooth_angle)
{
double gap = gap_width();
- double radius = gap/2;
- double line_length = gear_for_point->GetClearanceMM() - radius;
+ double radius = gap/3;
+ double clearance = gear_for_point->GetClearanceMM();
+ double line_length = clearance - radius;
+ if(line_length < 0.0)
+ {
+ line_length = 0.0;
+ radius = clearance;
+ }
+
gp_Pnt p1, p2, p1B, p2B;
get_clearance_points(p1, p2, tooth_angle, 0.0);
get_clearance_points(p1B, p2B, tooth_angle, line_length);
gp_Pnt pm = mid_point(tooth_angle, line_length);
gp_Circ c(gp_Ax2(pm, gp_Dir(0, 0, -1)), radius);
- if(line_length < wxGetApp().m_geom_tol)
- {
- radius = gear_for_point->GetClearanceMM();
- if(line_length > 0)line_length = 0;
- double mid_span_line_length = gap - 2*radius;
- if(mid_span_line_length >= wxGetApp().m_geom_tol)
- {
- gp_Vec v(p1, p2);
- v.Normalize();
- gp_Pnt p1C, p2C;
- get_clearance_points(p1C, p2C, tooth_angle,
gear_for_point->GetClearanceMM());
- gp_Pnt two_arc_p1 = gp_Pnt(p1C.XYZ() + v.XYZ() * radius);
- gp_Pnt two_arc_p2 = gp_Pnt(two_arc_p1.XYZ() + v.XYZ() *
mid_span_line_length);
- gp_Pnt pm1 = gp_Pnt(p1.XYZ() + v.XYZ() * radius);
- gp_Pnt pm2 = gp_Pnt(pm1.XYZ() + v.XYZ() * mid_span_line_length);
- gp_Circ c1(gp_Ax2(pm1, gp_Dir(0, 0, -1)), radius);
- gp_Circ c2(gp_Ax2(pm2, gp_Dir(0, 0, -1)), radius);
- sketch_for_gear->Add(new HArc(p1, two_arc_p1, c1,
&wxGetApp().current_color), NULL);
- sketch_for_gear->Add(new HLine(two_arc_p1, two_arc_p2,
&wxGetApp().current_color), NULL);
- sketch_for_gear->Add(new HArc(two_arc_p2, p2, c2,
&wxGetApp().current_color), NULL);
- }
- else
- {
- sketch_for_gear->Add(new HArc(p1B, p2B, c, &wxGetApp().current_color),
NULL);
- }
+ if(line_length >= wxGetApp().m_geom_tol)
+ sketch_for_gear->Add(new HLine(p1, p1B, &wxGetApp().current_color),
NULL);
+
+ double mid_span_line_length = gap - 2*radius;
+ if(mid_span_line_length >= wxGetApp().m_geom_tol)
+ {
+ gp_Vec v(p1, p2);
+ v.Normalize();
+ gp_Pnt p1C, p2C;
+ get_clearance_points(p1C, p2C, tooth_angle, clearance);
+ gp_Pnt two_arc_p1 = gp_Pnt(p1C.XYZ() + v.XYZ() * radius);
+ gp_Pnt two_arc_p2 = gp_Pnt(two_arc_p1.XYZ() + v.XYZ() *
mid_span_line_length);
+ gp_Pnt pm1 = gp_Pnt(p1B.XYZ() + v.XYZ() * radius);
+ gp_Pnt pm2 = gp_Pnt(pm1.XYZ() + v.XYZ() * mid_span_line_length);
+ gp_Circ c1(gp_Ax2(pm1, gp_Dir(0, 0, -1)), radius);
+ gp_Circ c2(gp_Ax2(pm2, gp_Dir(0, 0, -1)), radius);
+ sketch_for_gear->Add(new HArc(p1B, two_arc_p1, c1,
&wxGetApp().current_color), NULL);
+ sketch_for_gear->Add(new HLine(two_arc_p1, two_arc_p2,
&wxGetApp().current_color), NULL);
+ sketch_for_gear->Add(new HArc(two_arc_p2, p2B, c2,
&wxGetApp().current_color), NULL);
}
else
{
- sketch_for_gear->Add(new HLine(p1, p1B, &wxGetApp().current_color),
NULL);
sketch_for_gear->Add(new HArc(p1B, p2B, c, &wxGetApp().current_color),
NULL);
- sketch_for_gear->Add(new HLine(p2B, p2, &wxGetApp().current_color),
NULL);
- }
+ }
+
+ if(line_length >= wxGetApp().m_geom_tol)
+ sketch_for_gear->Add(new HLine(p2B, p2, &wxGetApp().current_color),
NULL);
spline_points_for_gear.clear();
spline_points_for_gear.push_back(p2);
@@ -341,10 +341,10 @@
// incremental_angle - to space the middle point at a quarter of a cycle
double incremental_angle = 0.5*Pi/gear_for_point->m_num_teeth -
middle_phi_and_angle.angle;
double angle1 = tooth_angle - (inside_phi_and_angle.angle +
incremental_angle);
-// double angle2 = tooth_angle + (inside_phi_and_angle.angle +
incremental_angle);
+ //double angle2 = tooth_angle + (inside_phi_and_angle.angle +
incremental_angle);
double angle3 = tooth_angle + (outside_phi_and_angle.angle +
incremental_angle);
double angle4 = next_tooth_angle - (outside_phi_and_angle.angle +
incremental_angle);
- double angle5 = next_tooth_angle - (inside_phi_and_angle.angle +
incremental_angle);
+ //double angle5 = next_tooth_angle - (inside_phi_and_angle.angle +
incremental_angle);
if(!make_closed_tooth_form && fabs(gear_for_point->GetClearanceMM()) >
0.0000000001)
{
@@ -380,25 +380,16 @@
involute(next_tooth_angle - incremental_angle, true);
add_spline();
-
- if(make_closed_tooth_form)
- {
- double inside_ring_radius = gear_for_point->m_inner_ring/2;
- int num_steps = 10;
- for(int i = 0; i<=num_steps; i++)
- {
- double angle = angle5 + (angle1 - angle5) * i / num_steps;
- point_at_rad_and_angle(inside_ring_radius, angle);
- }
- point_at_rad_and_angle(inside_radius, angle1);
- }
}
void HGear::SetSegmentsVariables(void(*callbackfunc)(const double *p))const
{
callbackfunc_for_point = callbackfunc;
gear_for_point = this;
+ gp_Trsf rotation;
+ rotation.SetRotation(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), m_angle *
Pi/180);
mat_for_point = make_matrix(m_pos.Location(), m_pos.XDirection(),
m_pos.YDirection());
+ mat_for_point = rotation.Multiplied(mat_for_point);
cone_sin_for_point = sin(m_cone_half_angle);
cone_cos_for_point = cos(m_cone_half_angle);
@@ -436,24 +427,16 @@
tooth(i, true, false);
}
+#ifdef GEAR_SKETCH_BIARCS
+ CSketch *sketch_with_biarcs = sketch_for_gear->SplineToBiarcs(0.01);
+ delete sketch_for_gear;
+ sketch_for_gear = NULL;
+ return sketch_with_biarcs;
+#else
CSketch* sketch = sketch_for_gear;
sketch_for_gear = NULL;
return sketch;
-}
-
-void HGear::GetInnerRingSegments(void(*callbackfunc)(const double *p),
double pixels_per_mm, bool want_start_point)const
-{
- SetSegmentsVariables(callbackfunc);
-
- double inner_ring_radius = this->m_inner_ring/2;
-
- int num = 10*m_num_teeth;
- for(int i = 0; i<=num; i++)
- {
- double angle = 2*Pi*i/num;
-
- if(i!=0 || want_start_point)point(cos(angle)*inner_ring_radius,
sin(angle)*inner_ring_radius);
- }
+#endif
}
void HGear::GetOneToothSegments(void(*callbackfunc)(const double *p),
double pixels_per_mm, bool want_start_point)const
@@ -479,9 +462,6 @@
glBegin(GL_LINE_STRIP);
GetSegments(glVertexFunction, wxGetApp().GetPixelScale());
glEnd();
- glBegin(GL_LINE_STRIP);
- GetInnerRingSegments(glVertexFunction, wxGetApp().GetPixelScale());
- glEnd();
if(fabs(m_depth) > 0.000000000001)
{
@@ -489,9 +469,6 @@
glBegin(GL_LINE_STRIP);
GetSegments(glVertexFunction, wxGetApp().GetPixelScale());
glEnd();
- glBegin(GL_LINE_STRIP);
- GetInnerRingSegments(glVertexFunction, wxGetApp().GetPixelScale());
- glEnd();
}
if(marked){
@@ -548,30 +525,10 @@
static void on_set_module(double value, HeeksObj* object){
((HGear*)object)->m_module = value;
}
-
-static void on_set_clearance(double value, HeeksObj* object){
- ((HGear*)object)->m_clearance = value;
-}
-
-static void on_set_addendum_offset(double value, HeeksObj* object){
- ((HGear*)object)->m_addendum_offset = value;
-}
-
-static void on_set_addendum_multiplier(double value, HeeksObj* object){
- ((HGear*)object)->m_addendum_multiplier = value;
-}
-
-static void on_set_dedendum_multiplier(double value, HeeksObj* object){
- ((HGear*)object)->m_dedendum_multiplier = value;
-}
static void on_set_pressure_angle(double value, HeeksObj* object){
((HGear*)object)->m_pressure_angle = value * Pi/180;
}
-
-static void on_set_spacing(double value, HeeksObj* object){
- ((HGear*)object)->m_spacing = value;
-}
static void on_set_tip_relief(double value, HeeksObj* object){
((HGear*)object)->m_tip_relief = value;
@@ -585,23 +542,17 @@
((HGear*)object)->m_cone_half_angle = value * Pi/180;
}
-static void on_set_inner_ring(double value, HeeksObj* object){
- ((HGear*)object)->m_inner_ring = value;
-}
-
+static void on_set_angle(double value, HeeksObj* object){
+ ((HGear*)object)->m_angle = value;
+}
void HGear::GetProperties(std::list<Property *> *list){
list->push_back(new PropertyInt(_("num teeth"), m_num_teeth, this,
on_set_num_teeth));
list->push_back(new PropertyDouble(_("module"), m_module, this,
on_set_module));
- list->push_back(new PropertyDouble(_("clearance"), m_clearance, this,
on_set_clearance));
- list->push_back(new PropertyDouble(_("addendum offset"),
m_addendum_offset, this, on_set_addendum_offset));
- list->push_back(new PropertyDouble(_("addendum multiplier"),
m_addendum_multiplier, this, on_set_addendum_multiplier));
- list->push_back(new PropertyDouble(_("dedendum multiplier"),
m_dedendum_multiplier, this, on_set_dedendum_multiplier));
list->push_back(new PropertyDouble(_("pressure angle"), m_pressure_angle
* 180/Pi, this, on_set_pressure_angle));
- list->push_back(new PropertyDouble(_("spacing"), m_spacing, this,
on_set_spacing));
list->push_back(new PropertyDouble(_("tip relief"), m_tip_relief, this,
on_set_tip_relief));
list->push_back(new PropertyDouble(_("depth"), m_depth, this,
on_set_depth));
list->push_back(new PropertyDouble(_("cone half angle"),
m_cone_half_angle * 180/Pi, this, on_set_cone_half_angle));
- list->push_back(new PropertyDouble(_("inner ring diameter"),
m_inner_ring, this, on_set_inner_ring));
+ list->push_back(new PropertyDouble(_("drawn angle"), m_angle, this,
on_set_angle));
HeeksObj::GetProperties(list);
}
@@ -645,7 +596,7 @@
if(oneTooth())
{
object_for_Tool->GetOneToothSegments(callbackfunc,
wxGetApp().GetPixelScale());
- wxGetApp().Add(sketch_for_make, NULL);
+ wxGetApp().Add(sketch_for_make, NULL);
}
else
{
@@ -699,16 +650,14 @@
element->SetAttribute("num_teeth", m_num_teeth);
element->SetDoubleAttribute("module", m_module);
- element->SetDoubleAttribute("clearance", m_clearance);
element->SetDoubleAttribute("addendum_offset", m_addendum_offset);
element->SetDoubleAttribute("addendum_multiplier", m_addendum_multiplier);
element->SetDoubleAttribute("dedendum_multiplier", m_dedendum_multiplier);
element->SetDoubleAttribute("pressure_angle", m_pressure_angle);
- element->SetDoubleAttribute("spacing", m_spacing);
element->SetDoubleAttribute("tip_relief", m_tip_relief);
element->SetDoubleAttribute("depth", m_depth);
element->SetDoubleAttribute("cone_half_angle", m_cone_half_angle);
- element->SetDoubleAttribute("inner_ring", m_inner_ring);
+ element->SetDoubleAttribute("drawn_angle", m_angle);
const gp_Pnt& l = m_pos.Location();
element->SetDoubleAttribute("lx", l.X());
@@ -735,16 +684,14 @@
element->Attribute("num_teeth", &new_object->m_num_teeth);
element->Attribute("module", &new_object->m_module);
- element->Attribute("clearance", &new_object->m_clearance);
element->Attribute("addendum_offset", &new_object->m_addendum_offset);
element->Attribute("addendum_multiplier",
&new_object->m_addendum_multiplier);
element->Attribute("dedendum_multiplier",
&new_object->m_dedendum_multiplier);
element->Attribute("pressure_angle", &new_object->m_pressure_angle);
- element->Attribute("spacing", &new_object->m_spacing);
element->Attribute("tip_relief", &new_object->m_tip_relief);
element->Attribute("depth", &new_object->m_depth);
element->Attribute("cone_half_angle", &new_object->m_cone_half_angle);
- element->Attribute("inner_ring", &new_object->m_inner_ring);
+ element->Attribute("drawn_angle", &new_object->m_angle);
double l[3] = {0.0, 0.0, 0.0};
double d[3] = {0.0, 0.0, 1.0};
@@ -769,3 +716,12 @@
return new_object;
}
+double HGear::GetClearanceMM()const
+{
+ // 12 teeth clearance 0.8
+ // 20 teeth clearance 0.55
+ // 52 teeth clearance 0.4
+ // 100000 teeth clearance 0.1
+
+ return (8.4 / ( 7.2 + m_num_teeth/2.5 )) * m_module;
+}
=======================================
--- /trunk/src/HGear.h Sun Nov 13 10:27:36 2011
+++ /trunk/src/HGear.h Mon Dec 19 22:06:04 2011
@@ -11,16 +11,14 @@
gp_Ax2 m_pos; // coordinate system defining position and orientation
int m_num_teeth;
double m_module;
- double m_clearance; // as a fraction of the module
double m_addendum_offset;
double m_addendum_multiplier;
double m_dedendum_multiplier;
double m_pressure_angle;
- double m_spacing;
double m_tip_relief;
double m_depth;
double m_cone_half_angle; // 0 for a cylinder ( spur gear ), 90 for a
circular rack
- double m_inner_ring; // a circle drawn in the middle of the gear with
this diameter
+ double m_angle; // draw the gear rotated anti-clockwise by this angle
HGear();
HGear(const HGear &o);
@@ -47,8 +45,7 @@
void GetTools(std::list<Tool*>* t_list, const wxPoint* p);
static HeeksObj* ReadFromXMLElement(TiXmlElement* pElem);
- void GetInnerRingSegments(void(*callbackfunc)(const double *p), double
pixels_per_mm, bool want_start_point = true)const;
void GetOneToothSegments(void(*callbackfunc)(const double *p), double
pixels_per_mm, bool want_start_point = true)const;
HeeksObj* MakeSketch()const;
- double GetClearanceMM()const{return m_clearance * m_module;}
+ double GetClearanceMM()const;
};
=======================================
--- /trunk/src/HeeksCAD.cpp Sat Nov 5 00:07:11 2011
+++ /trunk/src/HeeksCAD.cpp Mon Dec 19 22:06:04 2011
@@ -221,6 +221,7 @@
m_icon_texture_number = 0;
m_extrude_to_solid = true;
m_revolve_angle = 360.0;
+ m_stl_save_as_binary = true;
{
@@ -418,6 +419,7 @@
config.Read(_T("InputUsesModalDialog"), &m_input_uses_modal_dialog, true);
config.Read(_T("DraggingMovesObjects"), &m_dragging_moves_objects, true);
+ config.Read(_T("STLSaveBinary"), &m_stl_save_as_binary, true);
HDimension::ReadFromConfig(config);
LoadSketchToolsSettings();
@@ -587,6 +589,7 @@
config.Write(_T("ExtrudeToSolid"), m_extrude_to_solid);
config.Write(_T("RevolveAngle"), m_revolve_angle);
config.Write(_T("SolidViewMode"), m_solid_view_mode);
+ config.Write(_T("STLSaveBinary"), m_stl_save_as_binary);
HDimension::WriteToConfig(config);
@@ -1518,7 +1521,76 @@
}
}
-void HeeksCADapp::SaveSTLFile(const std::list<HeeksObj*>& objects, const
wxChar *filepath, double facet_tolerance, double* scale)
+class NineFloatsThreeFloats
+{
+public:
+ float x[9];
+ float n[3];
+};
+static std::list<NineFloatsThreeFloats> binary_triangles;
+
+static void write_binary_triangle(const double* x, const double* n)
+{
+ NineFloatsThreeFloats t;
+ for(int i = 0; i<9; i++)t.x[i] = (float)(x[i]);
+ for(int i = 0; i<3; i++)t.n[i] = (float)(n[i]);
+ binary_triangles.push_back(t);
+}
+
+void HeeksCADapp::SaveSTLFileBinary(const std::list<HeeksObj*>& objects,
const wxChar *filepath, double facet_tolerance, double* scale)
+{
+#ifdef __WXMSW__
+ ofstream ofs(filepath, ios::binary);
+#else
+ ofstream ofs(Ttc(filepath), ios::binary);
+#endif
+
+ // write 80 characters ( could be anything )
+ char header[80] = "Binary STL file made with
HeeksCAD ";
+ ofs.write(header, 80);
+
+ // get all the triangles
+ for(std::list<HeeksObj*>::const_iterator It = objects.begin(); It !=
objects.end(); It++)
+ {
+ HeeksObj* object = *It;
+ object->GetTriangles(write_binary_triangle, facet_tolerance < 0 ?
m_stl_facet_tolerance : facet_tolerance);
+ }
+
+ // write the number of facets
+ unsigned int num_facets = binary_triangles.size();
+ ofs.write((char*)(&num_facets), 4);
+
+ for(std::list<NineFloatsThreeFloats>::iterator It =
binary_triangles.begin(); It != binary_triangles.end(); It++)
+ {
+ NineFloatsThreeFloats t = *It;
+
+ gp_Pnt p0(t.x[0], t.x[1], t.x[2]);
+ gp_Pnt p1(t.x[3], t.x[4], t.x[5]);
+ gp_Pnt p2(t.x[6], t.x[7], t.x[8]);
+ gp_Vec v1(p0, p1);
+ gp_Vec v2(p0, p2);
+ float n[3] = {0.0f, 0.0f, 1.0f};
+ try
+ {
+ gp_Vec norm = (v1 ^ v2).Normalized();
+ n[0] = (float)(norm.X());
+ n[1] = (float)(norm.Y());
+ n[2] = (float)(norm.Z());
+ }
+ catch(...)
+ {
+ }
+
+ ofs.write((char*)(n), 12);
+ ofs.write((char*)(t.x), 36);
+ short attr = 0;
+ ofs.write((char*)(&attr), 2);
+ }
+
+ binary_triangles.clear();
+}
+
+void HeeksCADapp::SaveSTLFileAscii(const std::list<HeeksObj*>& objects,
const wxChar *filepath, double facet_tolerance, double* scale)
{
#ifdef __WXMSW__
ofstream ofs(filepath);
@@ -1547,6 +1619,12 @@
ofs<<"endsolid"<<endl;
}
+
+void HeeksCADapp::SaveSTLFile(const std::list<HeeksObj*>& objects, const
wxChar *filepath, double facet_tolerance, double* scale, bool binary)
+{
+ if(binary)SaveSTLFileBinary(objects, filepath, facet_tolerance, scale);
+ else SaveSTLFileAscii(objects, filepath, facet_tolerance, scale);
+}
void HeeksCADapp::SaveCPPFile(const std::list<HeeksObj*>& objects, const
wxChar *filepath, double facet_tolerance)
{
@@ -1755,7 +1833,7 @@
}
else if(wf.EndsWith(_T(".stl")))
{
- SaveSTLFile(m_objects, filepath);
+ SaveSTLFile(m_objects, filepath, -1.0, NULL, m_stl_save_as_binary);
}
else if(wf.EndsWith(_T(".cpp")))
{
@@ -2712,6 +2790,11 @@
{
wxGetApp().mouse_wheel_forward_away = !value;
}
+
+void on_set_stl_save_binary(bool value, HeeksObj* object)
+{
+ wxGetApp().m_stl_save_as_binary = value;
+}
void on_set_reverse_zooming(bool value, HeeksObj* object)
{
@@ -3230,6 +3313,7 @@
file_options->m_list.push_back(dxf_options);
PropertyList* stl_options = new PropertyList(_("STL"));
stl_options->m_list.push_back(new PropertyDouble(_("stl save facet
tolerance"), m_stl_facet_tolerance, NULL, on_stl_facet_tolerance));
+ stl_options->m_list.push_back( new PropertyCheck(_("STL save binary"),
m_stl_save_as_binary, NULL, on_set_stl_save_binary));
file_options->m_list.push_back(stl_options);
file_options->m_list.push_back(new PropertyInt(_("auto save interval (in
minutes)"), m_auto_save_interval, NULL, on_set_auto_save_interval));
#ifdef MULTIPLE_OWNERS
=======================================
--- /trunk/src/HeeksCAD.h Sat Nov 5 00:07:11 2011
+++ /trunk/src/HeeksCAD.h Mon Dec 19 22:06:04 2011
@@ -139,6 +139,7 @@
bool ctrl_does_rotate; // true - rotate on Ctrl, pan when not Ctrl
false - rotate when not Ctrl, pan when Ctrl
bool m_allow_opengl_stippling;
SolidViewMode m_solid_view_mode;
+ bool m_stl_save_as_binary;
//gp_Trsf digitizing_matrix;
CoordinateSystem *m_current_coordinate_system;
@@ -310,7 +311,9 @@
void OnOpenButton();
bool OpenFile(const wxChar *filepath, bool import_not_open = false,
HeeksObj* paste_into = NULL, HeeksObj* paste_before = NULL, bool
retain_filename = true );
void SaveDXFFile(const wxChar *filepath);
- void SaveSTLFile(const std::list<HeeksObj*>& objects, const wxChar
*filepath, double facet_tolerance = -1.0, double* scale = NULL);
+ void SaveSTLFileBinary(const std::list<HeeksObj*>& objects, const wxChar
*filepath, double facet_tolerance = -1.0, double* scale = NULL);
+ void SaveSTLFileAscii(const std::list<HeeksObj*>& objects, const wxChar
*filepath, double facet_tolerance = -1.0, double* scale = NULL);
+ void SaveSTLFile(const std::list<HeeksObj*>& objects, const wxChar
*filepath, double facet_tolerance = -1.0, double* scale = NULL, bool binary
= true);
void SaveCPPFile(const std::list<HeeksObj*>& objects, const wxChar
*filepath, double facet_tolerance = -1.0);
void SavePyFile(const std::list<HeeksObj*>& objects, const wxChar
*filepath, double facet_tolerance = -1.0);
void SaveXMLFile(const std::list<HeeksObj*>& objects, const wxChar
*filepath, bool for_clipboard = false);
=======================================
--- /trunk/src/Sketch.cpp Mon Jun 20 16:12:27 2011
+++ /trunk/src/Sketch.cpp Mon Dec 19 22:06:04 2011
@@ -33,7 +33,8 @@
std::string("re-order"),
std::string("clockwise"),
std::string("counter-clockwise"),
- std::string("multiple")
+ std::string("multiple"),
+ std::string("has circles"),
};
CSketch::CSketch():m_order(SketchOrderTypeUnknown)
@@ -1130,3 +1131,28 @@
return fillet_done;
}
+
+CSketch* CSketch::SplineToBiarcs(double tolerance)const
+{
+ CSketch *new_sketch = new CSketch;
+
+ for(std::list<HeeksObj*>::const_iterator It = m_objects.begin(); It !=
m_objects.end(); It++)
+ {
+ HeeksObj* span = *It;
+ if(span->GetType() == SplineType)
+ {
+ std::list<HeeksObj*> new_spans;
+ ((HSpline*)span)->ToBiarcs(new_spans, tolerance);
+ for(std::list<HeeksObj*>::iterator ItS = new_spans.begin(); ItS !=
new_spans.end(); ItS++)
+ {
+ new_sketch->Add(*ItS, NULL);
+ }
+ }
+ else
+ {
+ new_sketch->Add(span->MakeACopy(), NULL);
+ }
+ }
+
+ return new_sketch;
+}
=======================================
--- /trunk/src/Sketch.h Sat Nov 5 00:07:11 2011
+++ /trunk/src/Sketch.h Mon Dec 19 22:06:04 2011
@@ -72,6 +72,7 @@
bool FilletAtPoint(const gp_Pnt& p, double rad);
static void ReverseObject(HeeksObj* object);
double GetArea()const;
+ CSketch* SplineToBiarcs(double tolerance)const;
};
class CSketchRelinker{
=======================================
--- /trunk/src/SolidTools.cpp Sat Nov 5 00:07:11 2011
+++ /trunk/src/SolidTools.cpp Mon Dec 19 22:06:04 2011
@@ -64,7 +64,7 @@
if(wf.EndsWith(_T(".stl")))
{
- wxGetApp().SaveSTLFile(objects, filepath);
+ wxGetApp().SaveSTLFile(objects, filepath, -1.0, NULL,
wxGetApp().m_stl_save_as_binary);
}
else if(wf.EndsWith(_T(".cpp")))
{