Exemplo n.º 1
0
static void	WriteCoords(std::wofstream &ofs)
{
	CBox box;
	GetWorldBox(box);

	if(!box.m_valid)
	{
		box = CBox(-100, -100, -50, 100, 100, 50);
	}
	else
	{
		while(box.Width() < 100){box.m_x[0] -= 5.0; box.m_x[3] += 5.0;}
		while(box.Height() < 100){box.m_x[1] -= 5.0; box.m_x[4] += 5.0;}
		box.m_x[2] -= 10.0;
	}

	ofs<<"toolpath.coords = Coords("<<box.MinX()<<", "<<box.MinY()<<", "<<box.MinZ()<<", "<<box.MaxX()<<", "<<box.MaxY()<<", "<<box.MaxZ()<<")\n";
}
Exemplo n.º 2
0
static void RenderGrid(const CViewPoint *view_point, double max_number_across, bool in_between_spaces, bool miss_main_lines, const HeeksColor *bg, const HeeksColor *cc, unsigned char brightness, int plane_mode){
	gp_Pnt sp[4];
	double zval = 0.5;
	wxSize size = wxGetApp().m_current_viewport->GetViewportSize();
	sp[0] = gp_Pnt(0, 0, zval);
	sp[1] = gp_Pnt(size.GetWidth(), 0, zval);
	sp[2] = gp_Pnt(size.GetWidth(), size.GetHeight(), zval);
	sp[3] = gp_Pnt(0, size.GetHeight(), zval);
	gp_Vec vx, vy;
	int plane_mode2 = view_point->GetTwoAxes(vx, vy, false, plane_mode);
	gp_Pnt datum(0, 0, 0);
	gp_Trsf orimat = wxGetApp().GetDrawMatrix(false);
	datum.Transform(orimat);
	orimat = make_matrix(datum, vx, vy);
	gp_Vec unit_forward = view_point->forwards_vector().Normalized();
	double plane_dp = fabs(gp_Vec(0, 0, 1).Transformed(orimat) * unit_forward);
	if(plane_dp < 0.3)return;
	gp_Pln plane(gp_Pnt(0, 0, 0).Transformed(orimat), gp_Vec(0, 0, 1).Transformed(orimat));
	{
		for(int i =0; i<4; i++){
			gp_Pnt p1 = view_point->glUnproject(sp[i]);
			sp[i].SetZ(0);
			gp_Pnt p2 = view_point->glUnproject(sp[i]);
			if(p1.Distance(p2) < 0.00000000001)return;
			gp_Lin line = make_line(p1, p2);
			gp_Pnt pnt;
			if(intersect(line, plane, pnt))
			{
				sp[i].SetX((gp_Vec(pnt.XYZ()) * vx) - (gp_Vec(datum.XYZ()) * vx));
				sp[i].SetY((gp_Vec(pnt.XYZ()) * vy) - (gp_Vec(datum.XYZ()) * vy));
				sp[i].SetZ(0);
			}
		}
	}
	CBox b;
	{
		for(int i = 0; i<4; i++){
			b.Insert(sp[i].X(), sp[i].Y(), sp[i].Z());
		}
	}
	double width = b.Width();
	double height = b.Height();
	double biggest_dimension;
	if(height > width)biggest_dimension = height;
	else biggest_dimension = width;
	double widest_spacing = biggest_dimension/max_number_across;
	bool dimmer = false;
	double dimness_ratio = 1.0;
	double spacing;

	if(wxGetApp().draw_to_grid){
		spacing = wxGetApp().digitizing_grid;
		if(!miss_main_lines)spacing *= 10;
		if(spacing<0.0000000001)return;
		if(biggest_dimension / spacing > max_number_across * 1.5)return;
		if(biggest_dimension / spacing > max_number_across){
			dimmer = true;
			dimness_ratio = (max_number_across * 1.5 - biggest_dimension / spacing)/ (max_number_across * 0.5);
		}

	}
	else{
		double l = log10(widest_spacing / wxGetApp().m_view_units);

		double intl = (int)l;
		if(l>0)intl++;

		spacing = pow(10.0, intl) * wxGetApp().m_view_units;
	}

	if(wxGetApp().grid_mode == 3){
		dimmer = true;
		dimness_ratio *= plane_dp;
		dimness_ratio *= plane_dp;
	}
	double ext2d[4];
	ext2d[0] = b.m_x[0];
	ext2d[1] = b.m_x[1];
	ext2d[2] = b.m_x[3];
	ext2d[3] = b.m_x[4];
	{
		for(int i = 0; i<4; i++){
			double intval = (int)(ext2d[i]/spacing);
			if(i <2 ){
				if(ext2d[i]<0)intval--;
			}
			else{
				if(ext2d[i]>0)intval++;
			}

			ext2d[i] = intval * spacing;
		}
	}
	if(cc){
		HeeksColor col = *cc;
		if(wxGetApp().grid_mode == 3){
			switch(plane_mode2){
			case 0:
				col.green = (unsigned char)(0.6 * (double)(bg->green));
				break;
			case 1:
				col.red = (unsigned char)(0.9 * (double)(bg->red));
				break;
			case 2:
				col.blue = bg->blue;
				break;
			}
		}

		if(dimmer){
			double d_brightness = (double)brightness;
			d_brightness *= dimness_ratio;
			unsigned char uc_brightness = (unsigned char)d_brightness;

			glColor4ub(col.red, col.green, col.blue, uc_brightness);
		}
		else{
			glColor4ub(col.red, col.green, col.blue, brightness);
		}
	}
	glBegin(GL_LINES);
	double extra = 0;
	if(in_between_spaces)extra = spacing * 0.5;
	for(double x = ext2d[0] - extra; x<ext2d[2] + extra; x += spacing){
		if(miss_main_lines){
			double xr = x/spacing/5;
			if( fabs(  xr - (double)(int)(xr+ (xr>0 ? 0.5:-0.5)) ) < 0.1)continue;
		}
		gp_Pnt temp(datum.XYZ() + (vx.XYZ() * x) + (vy.XYZ() * ext2d[1]));
		glVertex3d(temp.X(), temp.Y(), temp.Z());
		temp = (datum.XYZ() + (vx.XYZ() * x) + (vy.XYZ() * ext2d[3]));
		glVertex3d(temp.X(), temp.Y(), temp.Z());
	}
	for(double y = ext2d[1] - extra; y<ext2d[3] + extra; y += spacing){
		if(miss_main_lines){
			double yr = y/spacing/5;
			if( fabs(  yr - (double)(int)(yr+(yr>0 ? 0.5:-0.5)) ) < 0.1)continue;
		}
		gp_Pnt temp = (datum.XYZ() + (vx.XYZ() * ext2d[0]) + (vy.XYZ() * y));
		glVertex3d(temp.X(), temp.Y(), temp.Z());
		temp = (datum.XYZ() + (vx.XYZ() * ext2d[2]) + (vy.XYZ() * y));
		glVertex3d(temp.X(), temp.Y(), temp.Z());
	}
	glEnd();
}
Exemplo n.º 3
0
static void	WriteSolids(std::wofstream &ofs)
{

	std::set<int> stock_ids;
	wxGetApp().m_program->Stocks()->GetSolidIds(stock_ids);
	for(std::set<int>::iterator It = stock_ids.begin(); It != stock_ids.end(); It++)
	{
		int id = *It;
		HeeksObj* object = wxGetApp().GetIDObject(SolidType, id);
		if(object)
		{
			CBox box;
			object->GetBox(box);
			ofs<<"voxelcut.set_current_color("<<object->GetColor()->COLORREF_color()<<")\n";
			double c[3];
			box.Centre(c);
			ofs<<"toolpath.coords.add_block("<<c[0]<<", "<<c[1]<<", "<<box.MinZ()<<", "<<box.Width()<<", "<<box.Height()<<", "<<box.Depth()<<")\n";
		}
	}
}
Exemplo n.º 4
0
void CBOM::Pack(double bin_width, double height, int gap)
{
    m_gap = gap;
    Rectangles_t best_rects;
    rects.clear();
    HeeksObj* child = GetFirstChild();
    while(child)
    {
        CTrsfNCCode* code = (CTrsfNCCode*)child;
        CBox box;
        code->GetBox(box);
        //Figure out how to translate later
        NCRect ncrect(0,0,box.Width()+gap,box.Height()+gap,code);
        best_rects.push_back(ncrect);
        rects.push_back(ncrect);
        child = GetNextChild();
    }


    // Sort by height.
    std::sort(best_rects.begin(),best_rects.end(),ByHeight());


    // Make variables to track and record the best solution.
    bool* is_positioned = new bool[best_rects.size()];
    for(unsigned int i=0; i < best_rects.size(); i++)
        is_positioned[i] = false;
    int num_unpositioned = rects.size();
    // Fill by stripes.
    int max_y = 0;
    for (unsigned int i = 0; i <= rects.size() - 1; i++)
    {
        // See if this rectangle is positioned.
        if (!is_positioned[i])
        {
            // Start a new stripe.
            num_unpositioned -= 1;
            is_positioned[i] = true;
            best_rects[i].m_x = 0;
            best_rects[i].m_y = max_y;

            FillBoundedArea(
                best_rects[i].m_width, bin_width, max_y,
                max_y + best_rects[i].m_height,
                num_unpositioned, best_rects, is_positioned,0, false);

            if (num_unpositioned == 0) break;
            max_y += best_rects[i].m_height;
        }
    }

    // Save the best solution.
    rects = best_rects;

    //Apply to the NCCODE
    for(unsigned int i=0; i < rects.size(); i++)
    {
        CTrsfNCCode *code = rects[i].m_code;
        CBox box;
        code->GetBox(box);
        code->m_x = rects[i].m_x - box.MinX();
        code->m_y = rects[i].m_y - box.MinY();
    }
}