Пример #1
0
// 自定义线程函数
//
DWORD WINAPI MyShatterThread(LPVOID lpParameter)
{
	CTool *pTool = (CTool *)lpParameter;  // 参数传递转换

	FILE *pWrite;  // 文件写指针
	// 以二进制可写方式打开文件,先将打开的文件内容清空,
	// 再往里写数据
	fopen_s(&pWrite, pTool->m_FilePath, "wb");
	// 设置文件指针位置为文件头
	fseek(pWrite, 0, SEEK_SET);

	// 如果文件指针创建失败,则返回0
	if(pWrite == NULL)
	{
		return 0;
	}

	DWORD cout = pTool->m_FileSize/100;  // 商,代表文件每百分之一的大小
	DWORD mod = pTool->m_FileSize%100;  // 余数
	// 设置进度条控件的范围
	pTool->m_ShatterProgress.SetRange(0,100);
	DWORD ByteWritten=0;  // 记录被修改的字节数
	CString strProgress;  // 用于显示进度的字符串

	// 显示进度
	for (DWORD j=1;j<=100;j++)
	{
		for (DWORD k=1;k<=cout;k++)
		{
			// 写入0
			fputc(0,pWrite);
			// 记录被修改的字节数
			ByteWritten++;
		}
		// 进度条显示进度
		pTool->m_ShatterProgress.SetPos(j);
		strProgress.Format("%d%s",j,"%");
		// 进度文本框显示进度
		pTool->SetDlgItemText(IDC_STATICDIGITAL,strProgress);
	}

	// 处理余下的字节
	for (DWORD y=1;y<=mod;y++)
	{
		// 写入0
		fputc(0,pWrite);
		// 记录被修改的字节数
		ByteWritten++;
	}

	fclose(pWrite);  // 关闭文件写指针

	if (ByteWritten == pTool->m_FileSize) 
	{
		// 使能粉碎按钮,恢复正常
		::EnableWindow(pTool->m_Shatter,TRUE);
	}

	return 1;
}
Пример #2
0
Python CDepthOp::AppendTextToProgram()
{
	Python python;

    python << CSpeedOp::AppendTextToProgram();

	python << _T("depthparams = depth_params(");
	python << _T("float(") << m_depth_op_params.m_clearance_height / theApp.m_program->m_units << _T(")");
	python << _T(", float(") << m_depth_op_params.m_rapid_safety_space / theApp.m_program->m_units << _T(")");
    python << _T(", float(") << m_depth_op_params.m_start_depth / theApp.m_program->m_units << _T(")");
    python << _T(", float(") << m_depth_op_params.m_step_down / theApp.m_program->m_units << _T(")");
    python << _T(", float(") << m_depth_op_params.m_z_finish_depth / theApp.m_program->m_units << _T(")");
    python << _T(", float(") << m_depth_op_params.m_z_thru_depth / theApp.m_program->m_units << _T(")");
    python << _T(", float(") << m_depth_op_params.m_final_depth / theApp.m_program->m_units << _T(")");
	if(m_depth_op_params.m_user_depths.Len() == 0) python << _T(", None");
    else python << _T(", [") << m_depth_op_params.m_user_depths << _T("]");
	python << _T(")\n");

	CTool *pTool = CTool::Find( m_tool_number );
	if (pTool != NULL)
	{
		python << _T("tool_diameter = float(") << (pTool->CuttingRadius(true) * 2.0) << _T(")\n");
		python << _T("cutting_edge_angle = float(") << pTool->m_params.m_cutting_edge_angle<< _T(")\n");

	} // End if - then

	return(python);
}
Пример #3
0
void CPocket::set_initial_values(int tool_number)
{
    if (tool_number > 0)
    {
        CTool *pTool = CTool::Find(tool_number);
        if (pTool != NULL)
        {
            m_step_over = pTool->CuttingRadius() * 3.0 / 5.0;
        }
    }
}
Пример #4
0
void
CTool::SetValue(
	int32 value)
{
	D_OPERATION(("CTool::SetValue(%ld)\n", value));

	if (value != m_value)
	{
		if (Mode() == TRIGGER_MODE)
		{
			// trigger tools don't change their value
			return;
		}

		if ((Mode() == RADIO_MODE) && (Flags() & FORCE_SELECTION)
		 && (Value() == B_CONTROL_ON))
		{
			// radio mode with the force-selection flag set does not
			// allow 'turning off' the tool directly
			return;
		}

		m_value = value;

		if ((Mode() == RADIO_MODE) && (Value() == B_CONTROL_ON))
		{
			// turn off other tools in radio group
			CTool *tool;
			tool = PreviousTool();
			while (tool)
			{
				if (tool->m_value == B_CONTROL_ON)
				{
					tool->m_value = B_CONTROL_OFF;
					tool->ValueChanged();
				}
				tool = tool->PreviousTool();
			}
			tool = NextTool();
			while (tool)
			{
				if (tool->m_value == B_CONTROL_ON)
				{
					tool->m_value = B_CONTROL_OFF;
					tool->ValueChanged();
				}
				tool = tool->NextTool();
			}
		}
		ValueChanged();
	}	
}
Пример #5
0
static void	WriteTools(std::wofstream &ofs)
{
	ofs<<"GRAY = 0x505050\n";
	ofs<<"RED = 0x600000\n";
	ofs<<"BLUE = 0x000050\n";
	for(HeeksObj* object = wxGetApp().m_program->Tools()->GetFirstChild(); object != NULL; object = wxGetApp().m_program->Tools()->GetNextChild())
	{
		if(object->GetType() == ToolType)
		{
			CTool* tool = (CTool*)object;
			ofs<<"toolpath.tools["<<tool->m_tool_number<<"] = "<<tool->VoxelcutDefinition().c_str()<<"\n";
		}
	}
}
Пример #6
0
void CToolDlg::OnTextCtrlEvent(wxCommandEvent& event)
{
	if(m_ignore_event_functions)return;

	// something's changed, recalculate the title
	CTool* object = (CTool*)(m_object->MakeACopy());
	GetData(object);
	m_ignore_event_functions = true;
	object->ResetTitle();
	m_txtTitle->SetValue(object->m_title);
	delete object;

	m_ignore_event_functions = false;
}
Пример #7
0
Python CWaterline::AppendTextToProgram(CMachineState *pMachineState)
{
	Python python;

    ReloadPointers();   // Make sure all the solids in m_solids are included as child objects.

	CTool *pTool = CTool::Find(m_tool_number);
	if(pTool == NULL)
	{
		return(python);
	}

	python << CDepthOp::AppendTextToProgram(pMachineState);

	// write the corner radius
	python << _T("corner_radius = float(");
	double cr = pTool->m_params.m_corner_radius - pTool->m_params.m_flat_radius;
	if(cr<0)cr = 0.0;
	python << ( cr / theApp.m_program->m_units ) << _T(")\n");

	heeksCAD->CreateUndoPoint();

	//write stl file
	std::list<HeeksObj*> solids;
	for (HeeksObj *object = GetFirstChild(); object != NULL; object = GetNextChild())
	{
	    if (object->GetType() != SolidType && object->GetType() != StlSolidType)
	    {
	        continue;
	    }

		if (object != NULL)
		{
			// Need to rotate a COPY of the solid by the fixture settings.
			HeeksObj* copy = object->MakeACopy();
			if (copy != NULL)
			{
				double m[16];	// A different form of the transformation matrix.
				CFixture::extract( pMachineState->Fixture().GetMatrix(CFixture::YZ), m );
                copy->ModifyByMatrix(m);

                CFixture::extract( pMachineState->Fixture().GetMatrix(CFixture::XZ), m );
                copy->ModifyByMatrix(m);

                CFixture::extract( pMachineState->Fixture().GetMatrix(CFixture::XY), m );
                copy->ModifyByMatrix(m);

                solids.push_back(copy);
            } // End if - then
        } // End if - then
	} // End for


    wxStandardPaths standard_paths;
    wxFileName filepath( standard_paths.GetTempDir().c_str(), wxString::Format(_T("waterline%d.stl"), number_for_stl_file).c_str() );
	number_for_stl_file++;

	heeksCAD->SaveSTLFile(solids, filepath.GetFullPath(), m_params.m_tolerance);

	// We don't need the duplicate solids any more.  Delete them.
	for (std::list<HeeksObj*>::iterator l_itSolid = solids.begin(); l_itSolid != solids.end(); l_itSolid++)
	{
		heeksCAD->Remove( *l_itSolid );
	} // End for
	heeksCAD->Changed();

    python << _T("ocl_funcs.waterline( filepath = ") << PythonString(filepath.GetFullPath()) << _T(", ")
            << _T("tool_diameter = ") << pTool->CuttingRadius() * 2.0 << _T(", ")
            << _T("corner_radius = ") << pTool->m_params.m_corner_radius / theApp.m_program->m_units << _T(", ")
            << _T("step_over = ") << m_params.m_step_over / theApp.m_program->m_units << _T(", ")
            << _T("mat_allowance = ") << m_params.m_material_allowance / theApp.m_program->m_units << _T(", ")
            << _T("clearance = clearance, ")
            << _T("rapid_safety_space = rapid_safety_space, ")
            << _T("start_depth = start_depth, ")
            << _T("step_down = step_down, ")
            << _T("final_depth = final_depth, ")
            << _T("units = ") << theApp.m_program->m_units << _T(", ")
            << _T("x0 = ") << m_params.m_box.m_x[0] / theApp.m_program->m_units << _T(", ")
            << _T("y0 = ") << m_params.m_box.m_x[1] / theApp.m_program->m_units << _T(", ")
            << _T("x1 = ") << m_params.m_box.m_x[3] / theApp.m_program->m_units << _T(", ")
            << _T("y1 = ") << m_params.m_box.m_x[4] / theApp.m_program->m_units << _T(", ")
            << _T("tolerance = ") << m_params.m_tolerance << _T(")\n");

	return(python);
}
Пример #8
0
bool Excellon::ReadDataBlock( const std::string & data_block )
{
	std::string _data( data_block );
	std::string::size_type offset;
	while ((offset = _data.find('%')) != _data.npos) _data.erase(offset,1);
	while ((offset = _data.find('*')) != _data.npos) _data.erase(offset,1);
	while ((offset = _data.find(',')) != _data.npos) _data.erase(offset,1);
	while ((offset = _data.find(' ')) != _data.npos) _data.erase(offset,1);
	while ((offset = _data.find('\t')) != _data.npos) _data.erase(offset,1);
	while ((offset = _data.find('\r')) != _data.npos) _data.erase(offset,1);

	char buffer[1024];
	memset(buffer,'\0', sizeof(buffer));
	strcpy( buffer, data_block.c_str() );

	static gp_Pnt position(0.0,0.0,0.0);
	bool position_has_been_set = false;

	bool m02_found = false;
	bool swap_axis = false;
	bool mirror_image_x_axis = false;
	bool mirror_image_y_axis = false;
	unsigned int excellon_tool_number = 0;
	double tool_diameter = 0.0;

	while (_data.size() > 0)
	{
	    if (_data.substr(0,2) == "RT")
		{
			// Reset Tool Data
			_data.erase(0,2);
            m_tool_table_map.clear();
            m_active_tool_number = 0;
		}
		else if (_data.substr(0,4) == "FMAT")
		{
			// Ignore format
			_data.erase(0,4);
			char *end = NULL;
			unsigned long format = strtoul( _data.c_str(), &end, 10 );
			_data.erase(0, end - _data.c_str());
			printf("Ignoring Format %ld command\n", format );
		}
		else if (_data.substr(0,3) == "AFS")
		{
			// Ignore format
			_data.erase(0,3);
			printf("Ignoring Automatic Feeds and Speeds\n");
		}
		else if (_data.substr(0,3) == "CCW")
		{
			_data.erase(0,3);
			printf("Ignoring Counter-Clockwise routing\n");
		}
		else if (_data.substr(0,2) == "CP")
		{
			_data.erase(0,2);
			printf("Ignoring Cutter Compensation\n");
		}
		else if (_data.substr(0,6) == "DETECT")
		{
			_data.erase(0,6);
			printf("Ignoring Broken Tool Detection\n");
		}
        else if (_data.substr(0,2) == "DN")
		{
			_data.erase(0,2);
			printf("Ignoring Down Limit Set\n");
		}
		else if (_data.substr(0,6) == "DTMDIST")
		{
			_data.erase(0,6);
			printf("Ignoring Maximum Route Distance Before Tool Change\n");
		}
		else if (_data.substr(0,4) == "EXDA")
		{
			_data.erase(0,4);
			printf("Ignoring Extended Drill Area\n");
		}
		else if (_data.substr(0,3) == "FSB")
		{
			_data.erase(0,3);
			printf("Ignoring Feeds and Speeds Button OFF\n");
		}
		else if (_data.substr(0,4) == "HBCK")
		{
			_data.erase(0,4);
			printf("Ignoring Home Button Check\n");
		}
		else if (_data.substr(0,4) == "NCSL")
		{
			_data.erase(0,4);
			printf("Ignoring NC Slope Enable/Disable\n");
		}
		else if (_data.substr(0,4) == "OM48")
		{
			_data.erase(0,4);
			printf("Ignoring Override Part Program Header\n");
		}
		else if (_data.substr(0,5) == "OSTOP")
		{
			_data.erase(0,5);
			printf("Ignoring Optional Stop switch\n");
		}
		else if (_data.substr(0,6) == "OTCLMP")
		{
			_data.erase(0,6);
			printf("Ignoring Override Table Clamp\n");
		}
		else if (_data.substr(0,8) == "PCKPARAM")
		{
			_data.erase(0,8);
			printf("Ignoring Set up pecking tool,depth,infeed and retract parameters\n");
		}
        else if (_data.substr(0,2) == "PF")
		{
			_data.erase(0,2);
			printf("Ignoring Floating Pressure Foot Switch\n");
		}
		else if (_data.substr(0,3) == "PPR")
		{
			_data.erase(0,3);
			printf("Ignoring Programmable Plunge Rate Enable\n");
		}
		else if (_data.substr(0,3) == "PVS")
		{
			_data.erase(0,3);
			printf("Ignoring Pre-vacuum Shut-off Switch\n");
		}
		else if (_data.substr(0,3) == "RC")
		{
			_data.erase(0,3);
			printf("Ignoring Reset Clocks\n");
		}
		else if (_data.substr(0,3) == "RCP")
		{
			_data.erase(0,3);
			printf("Ignoring Reset Program Clocks\n");
		}
		else if (_data.substr(0,3) == "RCR")
		{
			_data.erase(0,3);
			printf("Ignoring Reset Run Clocks\n");
		}
		else if (_data.substr(0,2) == "RD")
		{
			_data.erase(0,2);
			printf("Ignoring Reset All Cutter Distances\n");
		}
		else if (_data.substr(0,2) == "RH")
		{
			_data.erase(0,2);
			printf("Ignoring Reset All Hit Counters\n");
		}
		else if (_data.substr(0,3) == "SBK")
		{
			_data.erase(0,3);
			printf("Ignoring Single Block Mode Switch\n");
		}
		else if (_data.substr(0,2) == "SG")
		{
			_data.erase(0,2);
			printf("Ignoring Spindle Group Mode\n");
		}
		else if (_data.substr(0,4) == "SIXM")
		{
			_data.erase(0,4);
			printf("Ignoring Input From External Source\n");
		}
		else if (_data.substr(0,2) == "UP")
		{
			_data.erase(0,2);
			printf("Ignoring Upper Limit Switch Set\n");
		}
		else if (_data.substr(0,2) == "ZA")
		{
			_data.erase(0,2);
			printf("Ignoring Auxiliary Zero\n");
		}
		else if (_data.substr(0,2) == "ZC")
		{
			_data.erase(0,2);
			printf("Ignoring Zero Correction\n");
		}
		else if (_data.substr(0,2) == "ZS")
		{
			_data.erase(0,2);
			printf("Ignoring Zero Preset\n");
		}
		else if (_data.substr(0,1) == "Z")
		{
			_data.erase(0,1);
			printf("Ignoring Zero Set\n");
		}
		else if (_data.substr(0,3) == "VER")
		{
			// Ignore version
			_data.erase(0,3);
			char *end = NULL;
			unsigned long version = strtoul( _data.c_str(), &end, 10 );
			_data.erase(0, end - _data.c_str());
			printf("Ignoring Version %ld command\n", version);
		}
		else if (_data.substr(0,6) == "TCSTON")
		{
			// Tool Change Stop - ON
			printf("Ignoring Tool Change Stop - ON command\n");
			_data.erase(0,6);
		}
		else if (_data.substr(0,7) == "TCSTOFF")
		{
			// Tool Change Stop - OFF
			printf("Ignoring Tool Change Stop - OFF command\n");
			_data.erase(0,7);
		}
		else if (_data.substr(0,5) == "ATCON")
		{
			// Automatic Tool Change - ON
			printf("Ignoring Tool Change - ON command\n");
			_data.erase(0,5);
		}
		else if (_data.substr(0,6) == "ATCOFF")
		{
			// Automatic Tool Change - OFF
			printf("Ignoring Tool Change - OFF command\n");
			_data.erase(0,6);
		}
		else if (_data.substr(0,3) == "M30")
		{
			// End of program
			_data.erase(0,3);
		}
		else if (_data.substr(0,1) == ";")
		{
			_data.erase(0,1);
			return(true);	// Ignore all subsequent comments until the end of line.
		}
		else if (_data.substr(0,4) == "INCH")
		{
			_data.erase(0,4);
			m_units = 25.4;	// Imperial
		}
		else if (_data.substr(0,6) == "METRIC")
		{
			_data.erase(0,6);
			m_units = 1.0;	// mm
		}
		else if (_data.substr(0,2) == "MM")
		{
			_data.erase(0,2);
			m_units = 1.0;	// mm
		}
		else if (_data.substr(0,2) == "TZ")
		{
			_data.erase(0,2);
			// In Excellon files, the TZ means that trailing zeroes are INCLUDED
			// while in RS274X format, it means they're OMITTED
			m_trailingZeroSuppression = false;
		}
		else if (_data.substr(0,2) == "LZ")
		{
			_data.erase(0,2);
			// In Excellon files, the LZ means that leading zeroes are INCLUDED
			// while in RS274X format, it means they're OMITTED
			m_leadingZeroSuppression = false;
		}
		else if (_data.substr(0,1) == "T")
		{
			_data.erase(0,1);
			char *end = NULL;
			excellon_tool_number = strtoul( _data.c_str(), &end, 10 );
			_data.erase(0, end - _data.c_str());
		}
		else if (_data.substr(0,1) == "C")
		{
			_data.erase(0,1);
			const char *end = NULL;
			tool_diameter = special_strtod( _data.c_str(), &end );
			_data.erase(0, end - _data.c_str());
		}
		else if (_data.substr(0,3) == "M02")
		{
			_data.erase(0,3);
			m02_found = true;
		}
		else if (_data.substr(0,3) == "M00")
		{
			// End of program
			_data.erase(0,3);
		}
		else if ((_data.substr(0,3) == "M25") ||
			 (_data.substr(0,3) == "M31") ||
			 (_data.substr(0,3) == "M08") ||
			 (_data.substr(0,3) == "M01"))
		{
			// Beginning of pattern
			printf("Pattern repetition is not yet supported\n");
			return(false);
		}
		else if (_data.substr(0,1) == "R")
		{
			_data.erase(0,1);
			printf("Pattern repetition is not yet supported\n");
			return(false);

			/*
			char *end = NULL;
			repetitions = strtoul( _data.c_str(), &end, 10 );
			_data.erase(0, end - _data.c_str());
			*/
		}
		else if (_data.substr(0,3) == "M70")
		{
			_data.erase(0,3);
			swap_axis = true;
		}
		else if (_data.substr(0,3) == "M80")
		{
			_data.erase(0,3);
			mirror_image_x_axis = true;
		}
		else if (_data.substr(0,3) == "G90")
		{
			_data.erase(0,3);
			mirror_image_y_axis = true;
		}
		else if (_data.substr(0,1) == "N")
		{
			// Ignore block numbers
			_data.erase(0,1);
			char *end = NULL;
			strtoul( _data.c_str(), &end, 10 );
			_data.erase( 0, end - _data.c_str() );
		}
		else if (_data.substr(0,1) == "X")
		{
			_data.erase(0,1);	// Erase X
			const char *end = NULL;

			double x = special_strtod( _data.c_str(), &end );
			if ((end == NULL) || (end == _data.c_str()))
			{
				printf("Expected number following 'X'\n");
				return(false);
			} // End if - then
			std::string x_string = _data.substr(0, end - _data.c_str());
			_data.erase(0, end - _data.c_str());

            position_has_been_set = true;
            if (x_string.find('.') == std::string::npos)
            {

                double x = InterpretCoord( x_string.c_str(),
                                m_YDigitsLeftOfPoint,
                                m_YDigitsRightOfPoint,
                                m_leadingZeroSuppression,
                                m_trailingZeroSuppression );

                if (m_absoluteCoordinatesMode)
                {
                    position.SetX( x );
                }
                else
                {
                    // Incremental position.
                    position.SetX( position.X() + x );
                }
            }
            else
            {
                // The number had a decimal point explicitly defined within it.  Read it as a correctly
                // represented number as is.
                if (m_absoluteCoordinatesMode)
                {
                    position.SetX( x );
                }
                else
                {
                    // Incremental position.
                    position.SetX( position.X() + x );
                }
            }
		}
		else if (_data.substr(0,1) == "Y")
		{
			_data.erase(0,1);	// Erase Y
			const char *end = NULL;

			double y = special_strtod( _data.c_str(), &end );
			if ((end == NULL) || (end == _data.c_str()))
			{
				printf("Expected number following 'Y'\n");
				return(false);
			} // End if - then
			std::string y_string = _data.substr(0, end - _data.c_str());
			_data.erase(0, end - _data.c_str());

            position_has_been_set = true;
            if (y_string.find('.') == std::string::npos)
            {
                double y = InterpretCoord( y_string.c_str(),
                                m_YDigitsLeftOfPoint,
                                m_YDigitsRightOfPoint,
                                m_leadingZeroSuppression,
                                m_trailingZeroSuppression );

                if (m_absoluteCoordinatesMode)
                {
                    position.SetY( y );
                }
                else
                {
                    // Incremental position.
                    position.SetY( position.Y() + y );
                }
            }
            else
            {
                    // The number already has a decimal point explicitly defined within it.

                    if (m_absoluteCoordinatesMode)
                    {
                        position.SetY( y );
                    }
                    else
                    {
                        // Incremental position.
                        position.SetY( position.Y() + y );
                    }
            }
		}
		else if (_data.substr(0,3) == "G05")
		{
			_data.erase(0,3);
			printf("Ignoring select drill mode (G05) command\n");
		}
		else if (_data.substr(0,3) == "G81")
		{
			_data.erase(0,3);
			printf("Ignoring select drill mode (G81) command\n");
		}
		else if (_data.substr(0,3) == "G04")
		{
			_data.erase(0,3);
			printf("Ignoring variable dwell (G04) command\n");
		}
		else if (_data.substr(0,3) == "G90")
		{
			_data.erase(0,3);
			m_absoluteCoordinatesMode = true; 	// It's the only mode we use anyway.
		}
        else if (_data.substr(0,6) == "ICIOFF")
		{
			_data.erase(0,6);
			m_absoluteCoordinatesMode = true; 	// It's the only mode we use anyway.
		}
		else if (_data.substr(0,3) == "G91")    // Incremental coordinates mode ON
		{
			_data.erase(0,3);
			m_absoluteCoordinatesMode = false;
		}
		else if (_data.substr(0,5) == "ICION")    // Incremental coordinates mode ON
		{
			_data.erase(0,5);
			m_absoluteCoordinatesMode = false;
		}
		else if (_data.substr(0,3) == "G92")
		{
			_data.erase(0,3);
			printf("Set zero (G92) is not yet supported\n");
			return(false);
		}
		else if (_data.substr(0,3) == "G93")
		{
			_data.erase(0,3);
			printf("Set zero (G93) is not yet supported\n");
			return(false);
		}
		else if (_data.substr(0,3) == "M48")
		{
			_data.erase(0,3);
			// Ignore 'Program Header to first "%"'
		}
		else if (_data.substr(0,3) == "M47")
		{
			_data.erase(0,3);
			// Ignore 'Operator Message CRT Display'
			return(true);	// Ignore the rest of the line.
		}
		else if (_data.substr(0,3) == "M71")
		{
			_data.erase(0,3);
			m_units = 1.0;	// Metric
		}
		else if (_data.substr(0,3) == "M72")
		{
			_data.erase(0,3);
			m_units = 25.4;	// Imperial
		}
		else if (_data.substr(0,1) == "S")
		{
			_data.erase(0,1);
			const char *end = NULL;
			m_spindle_speed = special_strtod( _data.c_str(), &end );
			_data.erase(0, end - _data.c_str());
		}
		else if (_data.substr(0,1) == "F")
		{
			_data.erase(0,1);
			const char *end = NULL;
			m_feed_rate = special_strtod( _data.c_str(), &end ) * m_units;
			_data.erase(0, end - _data.c_str());
		}
		else
		{
			printf("Unexpected command '%s'\n", _data.c_str() );
			return(false);
		} // End if - else
	} // End while

    if (excellon_tool_number > 0)
	{
		// We either want to find an existing drill bit of this size or we need
		// to define a new one.

		if ((tool_diameter <= 0.0) && s_allow_dummy_tool_definitions)
		{
			// The file doesn't define the tool's diameter.  Just convert the tool number into a value in thousanths
			// of an inch and let it through.

			tool_diameter = (excellon_tool_number * 0.001);
		}

		bool found = false;
		for (HeeksObj *tool = theApp.m_program->Tools()->GetFirstChild(); tool != NULL; tool = theApp.m_program->Tools()->GetNextChild() )
		{
			// We're looking for a tool whose diameter is tool_diameter.
			CTool *pTool = (CTool *)tool;
			if (fabs(pTool->m_params.m_diameter - tool_diameter) < heeksCAD->GetTolerance())
			{
				// We've found it.
				// Keep a map of the tool numbers found in the Excellon file to those in our tool table.
				m_tool_table_map.insert( std::make_pair( excellon_tool_number, pTool->m_tool_number ));
				m_active_tool_number = pTool->m_tool_number;	// Use our internal tool number
				found = true;
				break;
			} // End if - then
		} // End for

        if ((! found) && (tool_diameter > 0.0))
        {
            // We didn't find an existing tool with the right diameter.  Add one now.
            int id = heeksCAD->GetNextID(ToolType);
            CTool *tool = new CTool(NULL, CToolParams::eDrill, id);
            heeksCAD->SetObjectID( tool, id );
            tool->SetDiameter( tool_diameter * m_units );
            theApp.m_program->Tools()->Add( tool, NULL );

            // Keep a map of the tool numbers found in the Excellon file to those in our tool table.
            m_tool_table_map.insert( std::make_pair( excellon_tool_number, tool->m_tool_number ));
            m_active_tool_number = tool->m_tool_number;	// Use our internal tool number
        }
	} // End if - then

	if (excellon_tool_number > 0)
	{
		// They may have selected a tool.
		m_active_tool_number = m_tool_table_map[excellon_tool_number];
	} // End if - then


	if (position_has_been_set)
	{
		if (m_active_tool_number <= 0)
		{
			printf("Hole position defined without selecting a tool first\n");
			return(false);
		} // End if - then
		else
		{
			// We've been given a position.  See if we already have a point object
			// at this location.  If so, use it.  Otherwise add a new one.
			CNCPoint cnc_point( position );
			if (m_mirror_image_x_axis) cnc_point.SetY( cnc_point.Y() * -1.0 ); // mirror about X axis
            if (m_mirror_image_y_axis) cnc_point.SetX( cnc_point.X() * -1.0 ); // mirror about Y axis

			if (m_existing_points.find( cnc_point ) == m_existing_points.end())
			{
				// There are no pre-existing Point objects for this location.  Add one now.
				double location[3];
				cnc_point.ToDoubleArray( location );
				HeeksObj *point = heeksCAD->NewPoint( location );
				heeksCAD->Add( point, NULL );
				CDrilling::Symbol_t symbol( point->GetType(), point->m_id );
				m_existing_points.insert( std::make_pair( cnc_point, symbol ));
			} // End if - then

			// There is already a point here.  Use it.
			if (m_holes.find( m_active_tool_number ) == m_holes.end())
			{
				// We haven't used this drill bit before.  Add it now.
				CDrilling::Symbols_t symbols;
				CDrilling::Symbol_t symbol( m_existing_points[ cnc_point ] );
				symbols.push_back( symbol );

				m_holes.insert( std::make_pair( m_active_tool_number, symbols ) );
			}
			else
			{
				// We've already used this drill bit.  Just add to its list of symbols.
				m_holes[ m_active_tool_number ].push_back( m_existing_points[ cnc_point ] );
			} // End if - else

			/*
			printf("Drill hole using tool %d at x=%lf, y=%lf z=%lf\n", m_active_tool_number,
				pPosition->X(), pPosition->Y(), pPosition->Z() );
			*/
		} // End if - else
	} // End if - then



	return(true);
} // End ReadDataBlock() method
Пример #9
0
LRESULT ActiveCombobox::WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
{
	switch (nMsg)
	{
	case WM_MOUSEACTIVATE:
		return MA_NOACTIVATE;

	case WM_DESTROY:
		{
			long nStart, nLength;
			SendMessage(CB_GETEDITSEL, (LPARAM)&nStart, (LPARAM)&nLength);
			m_pTool->tpV1.m_nSelStart = (short)nStart; 
			m_pTool->tpV1.m_nSelLength = (short)nLength;
			m_pTool->m_bPressed = FALSE;
			m_pTool->m_bDropDownPressed = FALSE;
			UnsubClass();
			LRESULT lResult = FWnd::WindowProc(nMsg, wParam, lParam);
			m_pTool->m_pBand->Refresh();
			m_pTool->m_pBar->m_pTabbedTool = NULL;
			RemoveFromMap();
			delete this;
			return lResult;
		}
		break;

	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hDC = BeginPaint(m_hWnd, &ps);
			if (hDC)
			{
				CRect rcClient;
				GetClientRect(rcClient);
				rcClient.Inflate(0, -1);
				ComboStyles nStyle;
				m_pTool->get_CBStyle(&nStyle);
				if (VARIANT_FALSE == m_pTool->m_pBar->bpV1.m_vbXPLook)
				{
					m_pTool->DrawCombo(hDC, 
									   rcClient, 
									   m_pTool->m_bDropDownPressed, 
									   0 != (nStyle == ddCBSReadOnly || nStyle == ddCBSSortedReadOnly));
				}
				else
				{
					m_pTool->DrawXPCombo(hDC, 
										 rcClient, 
										 m_pTool->m_bDropDownPressed, 
										 0 != (nStyle == ddCBSReadOnly || nStyle == ddCBSSortedReadOnly));
				}
				EndPaint(m_hWnd, &ps);
			}
			return 0;
		}
		break;
	
	case WM_COMMAND:
		{
			switch (HIWORD(wParam))
			{
			case CBN_CLOSEUP:
				{
					// Save the text
					LRESULT lResult = SendMessage(CB_GETCURSEL);
					CTool* pToolTemp = m_pTool;
					pToolTemp->GetComboList()->lpV1.m_nListIndex = (short)lResult;
					if (CB_ERR != lResult)
					{
						int nLen = SendMessage(CB_GETLBTEXTLEN, lResult, 0);
						if (0 != nLen)
						{
							TCHAR* szBuffer = new TCHAR[nLen+1];
							if (szBuffer)
							{
								try
								{
									lResult = SendMessage(CB_GETLBTEXT, lResult, (LPARAM)szBuffer);
									if (CB_ERR != lResult)
									{
										MAKE_WIDEPTR_FROMTCHAR(wBuffer, szBuffer);
										HRESULT hResult = pToolTemp->put_Text(wBuffer);
										assert(SUCCEEDED(hResult));
										if (SUCCEEDED(hResult))
										{
											pToolTemp->AddRef();
											::PostMessage(m_pTool->m_pBar->m_hWnd, GetGlobals().WM_ACTIVEBARTEXTCHANGE, 0, (LPARAM)m_pTool);
										}
									}
								}
								CATCH
								{
									assert(FALSE);
									REPORTEXCEPTION(__FILE__, __LINE__)
								}
								delete [] szBuffer;
							}
						}
					}

					try
					{
						// Fire the combo close event
						pToolTemp->m_pBar->FireToolComboClose((Tool*)pToolTemp);
					}
					catch (...)
					{
						assert(FALSE);
						REPORTEXCEPTION(__FILE__, __LINE__)
					}

					// Reset the tool
					pToolTemp->m_bPressed = FALSE;
					pToolTemp->m_bDropDownPressed = FALSE;
					if (IsWindow())
						ShowWindow(SW_HIDE);
				}
				break;

			case CBN_KILLFOCUS:
				SendMessage(WM_CANCELMODE);
				ShowWindow(SW_HIDE);
				break;

			case CBN_DROPDOWN:
				{
					m_pTool->m_bPressed = TRUE;
					m_pTool->m_bDropDownPressed = TRUE;
					CBList* pList = m_pTool->GetComboList();
					if (NULL == pList)
						break;

					int nPrevCount = pList->Count();

					m_pTool->m_pBar->FireComboDrop((Tool*)m_pTool);

					int nPrevLines = pList->lpV1.m_nLines;
					
					if (nPrevCount != pList->Count())
					{
						SendMessage(CB_RESETCONTENT, 0, 0);
						pList->m_hWndActive = m_hWnd;
						BSTR bstrItem;
						int nCount = pList->Count();
						for (int nItem = 0; nItem < nCount; nItem++)
						{
							bstrItem = pList->GetName(nItem);
							if (bstrItem)
							{
								MAKE_TCHARPTR_FROMWIDE(szItem, bstrItem);
								SendMessage(CB_ADDSTRING, 0, (LPARAM)szItem);
							}
						}
						switch (pList->lpV1.m_nStyle)
						{
						case ddCBSReadOnly:
						case ddCBSSortedReadOnly:
							{
								MAKE_TCHARPTR_FROMWIDE(szText, m_pTool->m_bstrText);
								int nIndex = SendMessage(CB_FINDSTRING, (WPARAM)-1, (LPARAM)szText);
								if (CB_ERR != nIndex)
									SendMessage(CB_SETCURSEL, nIndex, 0);
							}
							break;

						default:
							SendMessage(CB_SETCURSEL, pList->lpV1.m_nListIndex);
							break;
						}
					}
					if (nPrevLines == pList->lpV1.m_nLines)
						break;

					CRect rcCB;
					GetWindowRect(rcCB);
					int nItemHeight = SendMessage(CB_GETITEMHEIGHT, 0, 0);
					int nComboHeight = pList->lpV1.m_nLines * nItemHeight + rcCB.Height() + 2;
					::MoveWindow(m_hWnd,
								 0,
								 0,
								 rcCB.Width(),
								 nComboHeight,
								 FALSE);
				}
				break;

			case CBN_SELCHANGE:
				{
					try
					{
						int nIndex = SendMessage(CB_GETCURSEL);
						m_pTool->GetComboList()->lpV1.m_nListIndex = nIndex;
						assert (CB_ERR != nIndex);
						if (CB_ERR != nIndex)
						{
							int nLen = SendMessage(CB_GETLBTEXTLEN, nIndex, 0);
							assert(0 != nLen);
							if (0 != nLen)
							{
								TCHAR* szBuffer = new TCHAR[nLen + 1];
								assert(szBuffer);
								if (szBuffer)
								{
									HRESULT hResult;
									LRESULT lResult = SendMessage(CB_GETLBTEXT, nIndex, (LPARAM)szBuffer);
									assert(CB_ERR != lResult);
									if (CB_ERR != lResult)
									{
										MAKE_WIDEPTR_FROMTCHAR(wBuffer,szBuffer);
										hResult = m_pTool->put_Text(wBuffer);
										assert(SUCCEEDED(hResult));
									}
									UpdateWindow();
									delete szBuffer;
								}
							}
						}
						m_pTool->AddRef();
						::PostMessage(m_pTool->m_pBar->m_hWnd, GetGlobals().WM_ACTIVEBARCOMBOSELCHANGE, 0, (LPARAM)m_pTool);
					}
					catch (...)
					{
						assert(FALSE);
					}
				}
				break;

			case CBN_EDITCHANGE:
				{
					static bool m_bInExchange = FALSE;

					if (m_bInExchange)
						break;

					m_bInExchange = TRUE;

					// Transfer text
					HRESULT hResult;
					int nLen = SendMessage(WM_GETTEXTLENGTH);
					if (nLen > 0)
					{
						TCHAR* szBuffer = new TCHAR[nLen+1];
						if (NULL == szBuffer)
						{
							m_bInExchange = FALSE;
							break;
						}
						if (SendMessage(WM_GETTEXT, nLen+1, (LPARAM)szBuffer) > 0)
						{
							MAKE_WIDEPTR_FROMTCHAR(wBuffer, szBuffer);
							hResult = m_pTool->put_Text(wBuffer);
							if (SUCCEEDED(hResult))
							{
								m_pTool->AddRef();                     
								::PostMessage(m_pTool->m_pBar->m_hWnd, GetGlobals().WM_ACTIVEBARTEXTCHANGE, 0, (LPARAM)m_pTool);
							}
						}
						else
						{
							hResult = m_pTool->put_Text(L"");
							if (SUCCEEDED(hResult))
							{
								m_pTool->AddRef();                     
								::PostMessage(m_pTool->m_pBar->m_hWnd, GetGlobals().WM_ACTIVEBARTEXTCHANGE, 0, (LPARAM)m_pTool);
							}
						}
						delete [] szBuffer;
					}
					else
					{
						hResult = m_pTool->put_Text(L"");
						if (SUCCEEDED(hResult))
						{
							m_pTool->AddRef();                     
							::PostMessage(m_pTool->m_pBar->m_hWnd, GetGlobals().WM_ACTIVEBARTEXTCHANGE, 0, (LPARAM)m_pTool);
						}
					}

					m_bInExchange = FALSE;
				}
				break;
			}
		}
Пример #10
0
/**
	This method adjusts any parameters that don't make sense.  It should report a list
	of changes in the list of strings.
 */
std::list<wxString> CDrilling::DesignRulesAdjustment(const bool apply_changes)
{
	std::list<wxString> changes;

	// Make some special checks if we're using a chamfering bit.
	if (m_tool_number > 0)
	{
		CTool *pChamfer = (CTool *) CTool::Find( m_tool_number );
		if (pChamfer != NULL)
		{
			std::vector<CNCPoint> these_locations = CDrilling::FindAllLocations(this);

			if (pChamfer->m_params.m_type == CToolParams::eChamfer)
			{
				// We need to make sure that the diameter of the hole (that will
				// have been drilled in a previous drilling operation) is between
				// the chamfering bit's flat_radius (smallest) and diamter/2 (largest).

				// First find ALL drilling cycles that created this hole.  Make sure
				// to get them all as we may have used a centre drill before the
				// main hole is drilled.

				for (HeeksObj *obj = theApp.m_program->Operations()->GetFirstChild();
					obj != NULL;
					obj = theApp.m_program->Operations()->GetNextChild())
				{
					if (obj->GetType() == DrillingType)
					{
						// Make sure we're looking at a hole drilled with something
						// more than a centre drill.
						CToolParams::eToolType type = CTool::CutterType( ((COp *)obj)->m_tool_number );
						if (	(type == CToolParams::eDrill) ||
							(type == CToolParams::eEndmill) ||
							(type == CToolParams::eSlotCutter) ||
							(type == CToolParams::eBallEndMill))
						{
							// See if any of the other drilling locations line up
							// with our drilling locations.  If so, we must be
							// chamfering a previously drilled hole.

							std::vector<CNCPoint> previous_locations = CDrilling::FindAllLocations((CDrilling *)obj);
							std::vector<CNCPoint> common_locations;
							std::set_intersection( previous_locations.begin(), previous_locations.end(),
										these_locations.begin(), these_locations.end(),
										std::inserter( common_locations, common_locations.begin() ));
							if (common_locations.size() > 0)
							{
								// We're here.  We must be chamfering a hole we've
								// drilled previously.  Check the diameters.

								CTool *pPreviousTool = CTool::Find( ((COp *)obj)->m_tool_number );
								if (pPreviousTool->CuttingRadius() < pChamfer->m_params.m_flat_radius)
								{
#ifdef UNICODE
									std::wostringstream l_ossChange;
#else
									std::ostringstream l_ossChange;
#endif
									l_ossChange << _("Chamfering bit for drilling op") << " (id=" << m_id << ") " << _("is too big for previously drilled hole") << " (drilling id=" << obj->m_id << ")\n";
									changes.push_back( l_ossChange.str().c_str() );
								} // End if - then

								if (pPreviousTool->CuttingRadius() > (pChamfer->m_params.m_diameter/2.0))
								{
#ifdef UNICODE
									std::wostringstream l_ossChange;
#else
									std::ostringstream l_ossChange;
#endif
									l_ossChange << _("Chamfering bit for drilling op") << " (id=" << m_id << ") " << _("is too small for previously drilled hole") << " (drilling id=" << obj->m_id << ")\n";
									changes.push_back( l_ossChange.str().c_str() );
								} // End if - then
							} // End if - then

						} // End if - then
					} // End if - then
				} // End for
			} // End if - then
		} // End if - then
	} // End if - then

	if (m_tool_number > 0)
	{
		// Make sure the hole depth isn't greater than the tool's cutting depth.
		CTool *pDrill = (CTool *) CTool::Find( m_tool_number );
		if ((pDrill != NULL) && (pDrill->m_params.m_cutting_edge_height < m_params.m_depth))
		{
			// The drill bit we've chosen can't cut as deep as we've setup to go.

			if (apply_changes)
			{
#ifdef UNICODE
				std::wostringstream l_ossChange;
#else
				std::ostringstream l_ossChange;
#endif

				l_ossChange << _("Adjusting depth of drill cycle") << " id='" << m_id << "' " << _("from") << " '"
					<< m_params.m_depth / theApp.m_program->m_units << "' " << _("to") << " "
					<< pDrill->m_params.m_cutting_edge_height / theApp.m_program->m_units << "\n";
				changes.push_back(l_ossChange.str().c_str());

				m_params.m_depth = pDrill->m_params.m_cutting_edge_height;
			} // End if - then
			else
			{
#ifdef UNICODE
				std::wostringstream l_ossChange;
#else
				std::ostringstream l_ossChange;
#endif

				l_ossChange << _("WARNING") << ": " << _("Drilling") << " (id=" << m_id << ").  " << _("Can't drill hole") << " " << m_params.m_depth / theApp.m_program->m_units << " when the drill bit's cutting length is only " << pDrill->m_params.m_cutting_edge_height << " long\n";
				changes.push_back(l_ossChange.str().c_str());
			} // End if - else
		} // End if - then
	} // End if - then

	// See if there is anything in the reference objects that may be in conflict with this object's current configuration.
	for (Symbols_t::const_iterator l_itSymbol = m_symbols.begin(); l_itSymbol != m_symbols.end(); l_itSymbol++)
	{
		switch (l_itSymbol->first)
		{
			case ProfileType:
				{
					CProfile *pProfile = (CProfile *) heeksCAD->GetIDObject( l_itSymbol->first, l_itSymbol->second );
					if (pProfile != NULL)
					{
                        double depthOp_depth = ((CDepthOp *) pProfile)->m_depth_op_params.m_start_depth  - ((CDepthOp *) pProfile)->m_depth_op_params.m_final_depth;
                        if (depthOp_depth != m_params.m_depth)
                        {
    #ifdef UNICODE
                    std::wostringstream l_ossChange;
    #else
                    std::ostringstream l_ossChange;
    #endif

                            l_ossChange << _("Adjusting depth of drill cycle") << " (id='" << m_id << "') " << _("from") << " '"
                                << m_params.m_depth / theApp.m_program->m_units << "' " << _("to") << " '"
                                << depthOp_depth  / theApp.m_program->m_units<< "'\n";
                            changes.push_back(l_ossChange.str().c_str());

                            if (apply_changes)
                            {
                                m_params.m_depth = depthOp_depth;
                            } // End if - then
                        } // End if - then
					}
				}
				break;

			default:
				break;
		} // End switch
	} // End for

	// see wether combination of retract_mode, spindle_mode and peck_depth is valid:
	// move to design rule check
	if ((m_params.m_retract_mode == 1) || (m_params.m_spindle_mode == 1))
	{
		// if we feed retract, or stop the spindle at the bottom, this is a boring cycle.
		// cant have peck_depth > 0 then
		if (m_params.m_peck_depth > 0)
		{
#ifdef UNICODE
			std::wostringstream l_ossChange;
#else
			std::ostringstream l_ossChange;
#endif

			l_ossChange << _("WARNING") << ": " << _("cant have boring cycle with pecking > 0") << " (id=" << m_id << ")\n";
			changes.push_back(l_ossChange.str().c_str());

		}
	}



	return(changes);

} // End DesignRulesAdjustment() method
Пример #11
0
/**
	This method adjusts any parameters that don't make sense.  It should report a list
	of changes in the list of strings.
 */
std::list<wxString> CTapping::DesignRulesAdjustment(const bool apply_changes)
{
	std::list<wxString> changes;

	// Check that we're using a tapping tool and see if it's one of the standard sizes.
	if (m_tool_number > 0)
	{
		CTool *pTool = (CTool *) CTool::Find( m_tool_number );
		if (pTool != NULL)
		{
		    if (pTool->m_params.m_type != CToolParams::eTapTool)
		    {
		        changes.push_back(_("The tapping operation has not selected a tapping tool to use\n"));
		    }
		    else
		    {
		        // It is a tapping tool.  Check to see if the diameter and pitch combination match a standard size.

		        std::list<wxString> tool_check = pTool->DesignRulesAdjustment(apply_changes);
		        for (std::list<wxString>::iterator itChange = tool_check.begin(); itChange != tool_check.end(); itChange++)
		        {
		            changes.push_back(*itChange);
		        }
			
			// see wether tapping direction and spindle direction match
			if (pTool->m_params.m_direction && (m_speed_op_params.m_spindle_speed > 0)) 
			{
			    changes.push_back(_("Left-hand tapping needs a counterclockwise spindle rotation (negative spindle_speed)\n"));
			    if (apply_changes)
			    {
			        changes.push_back(_("Adjusting spindle rotation to counterclockwise.\n"));
				m_speed_op_params.m_spindle_speed  = - m_speed_op_params.m_spindle_speed;
			    } // End if - then
			}
			if (!pTool->m_params.m_direction && (m_speed_op_params.m_spindle_speed < 0) )
			{
			    changes.push_back(_("right-hand tapping needs clockwise spindle rotation (positive spindle_speed)\n"));
			    if (apply_changes)
			    {
				changes.push_back(_("Adjusting spindle rotation to clockwise.\n"));
				m_speed_op_params.m_spindle_speed  = - m_speed_op_params.m_spindle_speed;
			    } // End if - then
			}
		    }
		}
	}


	// Make some special checks if we're using a chamfering bit.
	if (m_tool_number > 0)
	{
		CTool *pTap = (CTool *) CTool::Find( m_tool_number );
		if (pTap != NULL)
		{
			std::vector<CNCPoint> these_locations = CDrilling::FindAllLocations(this);

			if (pTap->m_params.m_type == CToolParams::eTapTool)
			{
				// We need to make sure that the depth of the hole we're drilling is at least
				// as deep as the depth of our tapping operation.

				for (HeeksObj *obj = theApp.m_program->Operations()->GetFirstChild();
					obj != NULL;
					obj = theApp.m_program->Operations()->GetNextChild())
				{
					if (obj->GetType() == DrillingType)
					{
					    CDrilling *pDrilling = (CDrilling *) obj;

						// Make sure we're looking at a hole taped with something
						// more than a centre tap.
						CToolParams::eToolType type = CTool::CutterType( pDrilling->m_tool_number );
						if (	(type == CToolParams::eDrill) ||
							(type == CToolParams::eEndmill) ||
							(type == CToolParams::eSlotCutter) ||
							(type == CToolParams::eBallEndMill))
						{
							// See if any of the other drilling locations line up
							// with our tapping locations.  If so, we must be
							// tapping a previously drilled hole.

							std::vector<CNCPoint> previous_locations = CDrilling::FindAllLocations((CTapping *)obj);
							std::vector<CNCPoint> common_locations;
							std::set_intersection( previous_locations.begin(), previous_locations.end(),
										these_locations.begin(), these_locations.end(),
										std::inserter( common_locations, common_locations.begin() ));
							if (common_locations.size() > 0)
							{
								// We're here.  We must be tapping a hole we've
								// drilled previously.  Check the depths.

								if (pDrilling->m_params.m_depth < m_params.m_depth)
								{
								    wxString change;
								    change << _("ID ") << this->m_id << _(" The tapping operation's depth is greater than the previously drilled hole\n");
								    changes.push_back(change);
								}
							} // End if - then

						} // End if - then
					} // End if - then
				} // End for
			} // End if - then
		} // End if - then
	} // End if - then

	if (m_tool_number > 0)
	{
		// Make sure the hole depth isn't greater than the tool's cutting depth.
		CTool *pTap = (CTool *) CTool::Find( m_tool_number );
		if ((pTap != NULL) && (pTap->m_params.m_cutting_edge_height < m_params.m_depth))
		{
			// The drill bit we've chosen can't cut as deep as we've setup to go.

			if (apply_changes)
			{
#ifdef UNICODE
				std::wostringstream l_ossChange;
#else
				std::ostringstream l_ossChange;
#endif

				l_ossChange << _("Adjusting depth of tapping cycle") << " id='" << m_id << "' " << _("from") << " '"
					<< m_params.m_depth / theApp.m_program->m_units << "' " << _("to") << " "
					<< pTap->m_params.m_cutting_edge_height / theApp.m_program->m_units << "\n";
				changes.push_back(l_ossChange.str().c_str());

				m_params.m_depth = pTap->m_params.m_cutting_edge_height;
			} // End if - then
			else
			{
#ifdef UNICODE
				std::wostringstream l_ossChange;
#else
				std::ostringstream l_ossChange;
#endif

				l_ossChange << _("WARNING") << ": " << _("Tapping") << " (id=" << m_id << ").  " << _("Can't tap hole") << " " << m_params.m_depth / theApp.m_program->m_units << " when the tapping bit's cutting length is only " << pTap->m_params.m_cutting_edge_height << " long\n";
				changes.push_back(l_ossChange.str().c_str());
			} // End if - else
		} // End if - then
	} // End if - then


	return(changes);

} // End DesignRulesAdjustment() method
Пример #12
0
/**
	This method adjusts any parameters that don't make sense.  It should report a list
	of changes in the list of strings.
 */
std::list<wxString> CChamfer::DesignRulesAdjustment(const bool apply_changes)
{
	std::list<wxString> changes;

	// Make some special checks if we're using a chamfering bit.
	if (m_tool_number > 0)
	{
		CTool *pChamfer = (CTool *) CTool::Find( m_tool_number );
		if (pChamfer != NULL)
		{
			std::vector<CNCPoint> these_locations = CDrilling::FindAllLocations(this);

			if (pChamfer->m_params.m_type == CToolParams::eChamfer)
			{
				// We need to make sure that the diameter of the hole (that will
				// have been drilled in a previous drilling operation) is between
				// the chamfering bit's flat_radius (smallest) and diamter/2 (largest).

				// First find ALL drilling cycles that created this hole.  Make sure
				// to get them all as we may have used a centre drill before the
				// main hole is drilled.

				for (HeeksObj *obj = theApp.m_program->Operations()->GetFirstChild();
					obj != NULL;
					obj = theApp.m_program->Operations()->GetNextChild())
				{
					if (obj->GetType() == DrillingType)
					{
						// Make sure we're looking at a hole drilled with something
						// more than a centre drill.
						CToolParams::eToolType type = CTool::CutterType( ((COp *)obj)->m_tool_number );
						if (	(type == CToolParams::eDrill) ||
							(type == CToolParams::eEndmill) ||
							(type == CToolParams::eSlotCutter) ||
							(type == CToolParams::eBallEndMill))
						{
							// See if any of the other drilling locations line up
							// with our drilling locations.  If so, we must be
							// chamfering a previously drilled hole.

							std::vector<CNCPoint> previous_locations = CDrilling::FindAllLocations((CDrilling *)obj);
							std::vector<CNCPoint> common_locations;
							std::set_intersection( previous_locations.begin(), previous_locations.end(),
										these_locations.begin(), these_locations.end(),
										std::inserter( common_locations, common_locations.begin() ));
							if (common_locations.size() > 0)
							{
								// We're here.  We must be chamfering a hole we've
								// drilled previously.  Check the diameters.

								CTool *pPreviousTool = CTool::Find( ((COp *)obj)->m_tool_number );
								if (pPreviousTool->CuttingRadius() < pChamfer->m_params.m_flat_radius)
								{
									wxString change;
									change << DesignRulesPreamble() << _("Chamfering bit for drilling op") << _(" (id=") << m_id << _T(") ") << _("is too big for previously drilled hole") ;
									changes.push_back( change );
								} // End if - then

								if (pPreviousTool->CuttingRadius() > (pChamfer->m_params.m_diameter/2.0))
								{
									wxString change;
									change << DesignRulesPreamble() << _("Chamfering bit for drilling op") << _(" (id=") << m_id << _T(") ") << _("is too small for previously drilled hole");
									changes.push_back( change );
								} // End if - then
							} // End if - then

						} // End if - then
					} // End if - then
				} // End for
			} // End if - then
			else
			{
				wxString change;
				change << DesignRulesPreamble() << _("found with ") << pChamfer->m_params.m_type;
				changes.push_back(change);
			}
		} // End if - then
	} // End if - then

	std::list<wxString> extra_changes = CDepthOp::DesignRulesAdjustment(apply_changes);
	std::copy( extra_changes.begin(), extra_changes.end(), std::inserter( changes, changes.end() ));

	return(changes);

} // End DesignRulesAdjustment() method
Пример #13
0
Python CChamfer::AppendTextForCircularChildren(
	CMachineState *pMachineState,
	const double theta,
	HeeksObj *child,
	CTool *pChamferingBit )
{
	Python python;

	// See what the maximum possible depth is for this chamfering bit.  We want to figure
	// out whether we can cut with the middle part of the chamfering bit rather than
	// cutting using the very tip (we don't want to break it off).  In fact, we should
	// really cut with the top-most cutting edge so that it's as strong as it can be.  This
	// depends on the area available for fitting the chamfering bit.

	double min_chamfer_diameter = pChamferingBit->m_params.m_flat_radius * 2.0;
	double stand_off = m_depth_op_params.m_rapid_safety_space;
	double clearance_height = m_depth_op_params.ClearanceHeight();

	Circles_t circles;

	if (child->GetType() == DrillingType)
	{
		// Get the size of the drilled holes.  We need to know whether we need to just plunge
		// the chamfering bit directly down into the hole or whether we need to run
		// around the edge.

		CDrilling *pDrilling = (CDrilling *) child;
		CTool *pDrillBit = CTool::Find( pDrilling->m_tool_number );
		if (pDrillBit == NULL)
		{
			// It's difficult to drill a hole without a drill bit but apparently this file does.
			printf("Ignoring drilling operation (id=%d) with no  tool defined\n", pDrilling->m_id );
			return(python);	// Empty.
		}

        stand_off = pDrilling->m_params.m_standoff;
        clearance_height = pDrilling->m_params.ClearanceHeight();

		double hole_diameter = pDrillBit->CuttingRadius(false) * 2.0;

		if (hole_diameter < min_chamfer_diameter)
		{
			// The flat radius at the bottom of the chamfering bit is larger than the drilled hole.  It won't fit in.
			printf("Ignoring chamfer for drilled hole due to geometry of selected chamfering bit\n");
			return(python);	// Empty.
		}

		// Get all the point locations relevant for this operation and then adjust their position to align with
		// the current fixture.
		std::vector<CNCPoint> locations = CDrilling::FindAllLocations(pDrilling, pMachineState->Location(), true, NULL);
        for (std::vector<CNCPoint>::const_iterator l_itLocation = locations.begin(); l_itLocation != locations.end(); l_itLocation++)
		{
			CNCPoint point = pMachineState->Fixture().Adjustment( *l_itLocation );
			circles.push_back( Circle( point, hole_diameter, pDrilling->m_params.m_depth ) );
		} // End for
	} // End if - then

	if (child->GetType() == CounterBoreType)
	{
		CCounterBore *pCounterBore = ((CCounterBore *) child);

		stand_off = pCounterBore->m_depth_op_params.m_rapid_safety_space;
        clearance_height = pCounterBore->m_depth_op_params.ClearanceHeight();

		std::vector<CNCPoint> locations = CDrilling::FindAllLocations(pCounterBore, pMachineState->Location(), pCounterBore->m_params.m_sort_locations != 0, NULL);
		for (std::vector<CNCPoint>::const_iterator l_itLocation = locations.begin(); l_itLocation != locations.end(); l_itLocation++)
		{
			CNCPoint point = pMachineState->Fixture().Adjustment( *l_itLocation );
			double max_depth = pCounterBore->m_depth_op_params.m_start_depth - pCounterBore->m_depth_op_params.m_final_depth;
			circles.push_back( Circle( point, pCounterBore->m_params.m_diameter, max_depth ) );
		} // End for
	}

	// Now handle all the chamfering for both the drilled holes and/or the counterbores.
	// The circles indicate both the diameter and the depth of either hole.
	for (Circles_t::iterator l_itCircle = circles.begin(); l_itCircle != circles.end(); l_itCircle++)
	{
		// We want to select a depth such that we're cutting with the top-most part of the chamfering
		// bit as that is the strongest part.  We don't want to break off the tip unless we really can't
		// get into the hole without doing so.

		double max_hole_depth = l_itCircle->MaxDepth();
		double max_bit_plunge_depth = pChamferingBit->m_params.m_cutting_edge_height * cos(theta);

		double min_bit_radius = pChamferingBit->m_params.m_flat_radius;

		double hole_radius = l_itCircle->Diameter() / 2.0;
		double required_bit_plunge_depth =  (m_params.m_chamfer_width * cos( theta ));

		if ((required_bit_plunge_depth >= max_hole_depth) ||
			(required_bit_plunge_depth >= max_bit_plunge_depth) ||
			(hole_radius < min_bit_radius))
		{
			// It's too deep for one pass.
			return(python);	// Empty.
		}

		double plunge_depth = (max_hole_depth<=max_bit_plunge_depth)?max_hole_depth:max_bit_plunge_depth;
		double bit_radius_at_plunge_depth = pChamferingBit->m_params.m_flat_radius + (plunge_depth / tan(theta));

		// This is the gap between the bit and the hole when the bit's bottom is at the top surface.
		double gap_radius = hole_radius - min_bit_radius;

		// We need to figure out how far down to move before this gap is closed by the slope of the cutting edge.
		double gap_closure_depth = gap_radius / tan(theta);

		if ( hole_radius <= bit_radius_at_plunge_depth )
		{
			// We can plunge straight down at the hole's location.

			// If the chamfering bit is at the top of the hole then the diameter of
			// cut is equal to the flat radius.  How far should we plunge down before
			// the edge of the chamfering bit touches the top of the hole?

            CNCPoint point(l_itCircle->Location());

			python << _T("drill(")
				<< _T("x=") << point.X(true) << _T(", ")
				<< _T("y=") << point.Y(true) << _T(", ")
				<< _T("z=") << drawing_units(point.Z(false) - gap_closure_depth) << _T(", ")
				<< _T("depth=") << drawing_units(required_bit_plunge_depth) << _T(", ")
				<< _T("standoff=") << drawing_units(stand_off) << _T(", ")
				<< _T("dwell=") << 0.0 << _T(", ")
				<< _T("peck_depth=") << 0.0 << _T(", ")
                << _T("clearance_height=") << drawing_units(clearance_height)
				<< _T(")\n");
		}
		else
		{
			// We will have to run around the edge of the large hole.  Figure out the offset
			// in from the edge and generate the corresponding tool path.

			CNCPoint centre(l_itCircle->Location());
			CNCPoint point(l_itCircle->Location());

			double radius_of_spiral = hole_radius - bit_radius_at_plunge_depth + (m_params.m_chamfer_width * sin(theta));

			python << _T("rapid( x=") << centre.X(true) << _T(", ")
						<< _T("y=") << centre.Y(true) << _T(", ")
						<< _T("z=") << drawing_units(clearance_height) << _T(")\n");

            python << _T("rapid(z=") << drawing_units(stand_off) << _T(")\n");

			double cutting_depth = point.Z(false) - plunge_depth;

			// Move to 12 O'Clock.
			python << _T("feed( x=") << centre.X(true) << _T(", ")
						_T("y=") << drawing_units(centre.Y(false) + radius_of_spiral) << _T(", ")
						_T("z=") << drawing_units(cutting_depth) << _T(")\n");
			point.SetX( centre.X(false) );
			point.SetY( centre.Y(false) + radius_of_spiral );

			// First quadrant (12 O'Clock to 9 O'Clock)
			python << _T("arc_ccw( x=") << drawing_units(centre.X(false) - radius_of_spiral) << _T(", ") <<
						_T("y=") << centre.Y(true) << _T(", ") <<
						_T("z=") << drawing_units(cutting_depth) << _T(", ") <<	// full depth
						_T("i=") << drawing_units(centre.X(false)) << _T(", ") <<
						_T("j=") << drawing_units(centre.Y(false)) << _T(")\n");
			point.SetX( centre.X(false) - radius_of_spiral );
			point.SetY( centre.Y(false) );

			// Second quadrant (9 O'Clock to 6 O'Clock)
			python << _T("arc_ccw( x=") << centre.X(true) << _T(", ") <<
						_T("y=") << drawing_units(centre.Y(false) - radius_of_spiral) << _T(", ") <<
						_T("z=") << drawing_units(cutting_depth) << _T(", ") <<	// full depth now
						_T("i=") << drawing_units(centre.X(false)) << _T(", ") <<
						_T("j=") << drawing_units(centre.Y(false)) << _T(")\n");
			point.SetX( centre.X(false) );
			point.SetY( centre.Y(false) - radius_of_spiral );

			// Third quadrant (6 O'Clock to 3 O'Clock)
			python << _T("arc_ccw( x=") << drawing_units(centre.X(false) + radius_of_spiral) << _T(", ") <<
						_T("y=") << centre.Y(true) << _T(", ") <<
						_T("z=") << drawing_units(cutting_depth) << _T(", ") <<	// full depth now
						_T("i=") << drawing_units(centre.X(false)) << _T(", ") <<
						_T("j=") << drawing_units(centre.Y(false)) << _T(")\n");
			point.SetX( centre.X(false) + radius_of_spiral );
			point.SetY( centre.Y(false) );

			// Fourth quadrant (3 O'Clock to 12 O'Clock)
			python << _T("arc_ccw( x=") << centre.X(true) << _T(", ") <<
						_T("y=") << drawing_units(centre.Y(false) + radius_of_spiral) << _T(", ") <<
						_T("z=") << drawing_units(cutting_depth) << _T(", ") <<	// full depth now
						_T("i=") << drawing_units(centre.X(false)) << _T(", ") <<
						_T("j=") << drawing_units(centre.Y(false)) << _T(")\n");
			point.SetX( centre.X(false) );
			point.SetY( centre.Y(false) + radius_of_spiral );

			python << _T("rapid( z=") << drawing_units(m_depth_op_params.ClearanceHeight()) << _T(")\n");
		}
	} // End for

	return(python);
}
Пример #14
0
unsigned int CProfile::GetNumSketches()
{
	unsigned int num_sketches = 0;
#ifdef OP_SKETCHES_AS_CHILDREN
    for (HeeksObj *object = GetFirstChild(); object != NULL; object = GetNextChild())
    {
#else
	for (std::list<int>::iterator It = m_sketches.begin(); It != m_sketches.end(); It++)
    {
		HeeksObj* object = heeksCAD->GetIDObject(SketchType, *It);
#endif
		if(object && object->GetType() == SketchType)num_sketches++;
	}
	return num_sketches;
}

/**
	The old version of the CDrilling object stored references to graphics as type/id pairs
	that get read into the m_symbols list.  The new version stores these graphics references
	as child elements (based on ObjList).  If we read in an old-format file then the m_symbols
	list will have data in it for which we don't have children.  This routine converts
	these type/id pairs into the HeeksObj pointers as children.
 */
#ifdef OP_SKETCHES_AS_CHILDREN
void CProfile::ReloadPointers()
{
	for (Sketches_t::iterator symbol = m_sketches.begin(); symbol != m_sketches.end(); symbol++)
	{
		HeeksObj *object = heeksCAD->GetIDObject( SketchType, *symbol );
		if (object != NULL)
		{
			Add( object, NULL );
		}
	}

	m_sketches.clear();	// We don't want to convert them twice.

	CDepthOp::ReloadPointers();
}
#endif

/**
	If it's an 'inside' profile then we need to make sure the auto_roll_radius is not so large
	that it's going to gouge the part outside the sketch's area.  This routine only
	reduces the auto_roll_radius.  Its value is not changed unless a gouge scenario is detected.
 */
std::list<wxString> CProfile::ConfirmAutoRollRadius(const bool apply_changes)
{
#ifdef UNICODE
			std::wostringstream l_ossChange;
#else
			std::ostringstream l_ossChange;
#endif

	std::list<wxString> changes;

	if (m_profile_params.m_tool_on_side == CProfileParams::eRightOrInside)
	{
		// Look at the dimensions of the sketches as well as the diameter of the bit to decide if
		// our existing m_auto_roll_radius is too big for this profile.  If so, reduce it now.
		CTool *pTool = NULL;
		if ((m_tool_number > 0) && ((pTool = CTool::Find(m_tool_number)) != NULL))
		{
			for (std::list<int>::iterator l_itSketchId = m_sketches.begin(); l_itSketchId != m_sketches.end(); l_itSketchId++)
			{
				HeeksObj *sketch = heeksCAD->GetIDObject( SketchType, *l_itSketchId );
				if (sketch != NULL)
				{
					CBox bounding_box;
					sketch->GetBox( bounding_box );

					double min_distance_across = (bounding_box.Height() < bounding_box.Width())?bounding_box.Height():bounding_box.Width();
					double max_roll_radius = (min_distance_across - (pTool->CuttingRadius() * 2.0)) / 2.0;

					if (max_roll_radius < m_profile_params.m_auto_roll_radius)
					{
						l_ossChange << "Need to adjust auto_roll_radius for profile id=" << m_id << " from "
								<< m_profile_params.m_auto_roll_radius << " to " << max_roll_radius << "\n";
						changes.push_back(l_ossChange.str().c_str());

						if (apply_changes)
						{
							m_profile_params.m_auto_roll_radius = max_roll_radius;
						} // End if - then
					}
				} // End if - then
			} // End for
		} // End if - then
	} // End if - then

	return(changes);

} // End ConfirmAutoRollRadius() method
Пример #15
0
void
CAssemblyWindow::AddToolBar()
{
	BMessage *message;

	// make the pop up menu for 'Select' tool
	BPopUpMenu *selectMenu = new BPopUpMenu("", false, false);
	selectMenu->SetFont(be_plain_font);	
	message = new BMessage(SELECT_MODE_CHANGED);
	message->AddInt32("mev:mode", CEventEditor::RECTANGLE_SELECTION);
	selectMenu->AddItem(new CIconMenuItem("Rectangle", message,
										  ResourceUtils::LoadImage("ArrowTool")));
	message = new BMessage(*message);
	message->ReplaceInt32("mev:mode", CEventEditor::LASSO_SELECTION);
	selectMenu->AddItem(new CIconMenuItem("Lasso", message,
										  ResourceUtils::LoadImage("LassoTool")));
	selectMenu->SetTargetForItems(this);

	// make the pop up menu for 'Create' tool
	BPopUpMenu *createMenu = new BPopUpMenu("", false, false);
	createMenu->SetFont(be_plain_font);
	message = new BMessage(NEW_EVENT_TYPE_CHANGED);
	message->AddInt32("type", EvtType_Count);
	createMenu->AddItem(new CIconMenuItem("Default", message,
										  ResourceUtils::LoadImage("PencilTool")));
	createMenu->AddSeparatorItem();
	message = new BMessage(*message);
	message->ReplaceInt32("type", EvtType_Tempo);
	createMenu->AddItem(new CIconMenuItem("Tempo", message,
										  ResourceUtils::LoadImage("MetroTool")));
	message = new BMessage(*message);
	message->ReplaceInt32("type", EvtType_TimeSig);
	createMenu->AddItem(new CIconMenuItem("Time Signature", message,
										  ResourceUtils::LoadImage("TimeSigTool")));
	message = new BMessage(*message);
	message->ReplaceInt32("type", EvtType_Repeat);
	createMenu->AddItem(new CIconMenuItem("Repeat", message,
										  ResourceUtils::LoadImage("RepeatTool")));
	message = new BMessage(*message);
	message->ReplaceInt32("type", EvtType_End);
	createMenu->AddItem(new CIconMenuItem("Part End", message,
										  ResourceUtils::LoadImage("EndTool")));
	createMenu->SetTargetForItems(this);

	BRect rect(Bounds());
	if (KeyMenuBar())
		rect.top = KeyMenuBar()->Frame().bottom + 1.0;
	rect.right += 1.0;

	// add the tool bar
	CToolBar *toolBar = new CToolBar(rect, "General");
	CTool *tool;
	toolBar->AddTool(tool = new CBitmapTool("Snap To Grid",
											ResourceUtils::LoadImage("GridTool"),
											new BMessage(CEventEditor::TOOL_GRID)));
	tool->SetValue(B_CONTROL_ON);
	toolBar->AddSeparator();

	toolBar->AddTool(tool = new CMenuTool("Select",
										  ResourceUtils::LoadImage("ArrowTool"),
										  selectMenu,
										  new BMessage(CEventEditor::TOOL_SELECT)));
	tool->SetValue(B_CONTROL_ON);
	toolBar->AddTool(new CMenuTool("Create", ResourceUtils::LoadImage("PencilTool"),
								   createMenu, new BMessage(CEventEditor::TOOL_CREATE)));
	toolBar->AddTool(tool = new CBitmapTool("Eraser",
											ResourceUtils::LoadImage("EraserTool"),
											new BMessage(CEventEditor::TOOL_ERASE)));
	toolBar->MakeRadioGroup("Select", "Eraser", true);

	SetToolBar(toolBar);
}