|
- #include "stdafx.h"
- #include "ParserModuleHeader.h"
- #include "..\NcFile\NcFile.h"
- #include "..\CamWrapper\CamHoleWrapper.h"
- #include "..\CamWrapper\CamPathWrapper.h"
- #include "..\CamWrapper\CamSplineWrapper.h"
- #include "..\CamWrapper\CamWrapperSearcher.h"
- #include "..\CamWrapper\OverEdgeAdjust.h"
- #include <algorithm>
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- using namespace NcInterpAxes3;
-
- const CHAR c_szScanGxxNodes[] = "ScanCamGxxNodes";
-
- //////////////////////////////////////////////////////////////////////////
- void RetrieveArcInf(const DPOINT2& nxStart_, const DPOINT2& nxEnd_, double nBulge_,
- DPOINT2& nxCenter_, double& nStartAngle_, double& nEndAngle_, double& nRadius_)
- {
- DPOINT2 _nxFromTo = nxEnd_ - nxStart_;
- double _nChordLen = _nxFromTo.GetLength();
- ASSERT(DOUBLE_GE_ZERO(_nChordLen));
- if (DOUBLE_EQU_ZERO(_nChordLen))
- {
- // 弦长比较短的圆弧当作点处理
- nxCenter_ = nxStart_;
- nStartAngle_ = 0.;
- nEndAngle_ = 0.;
- nRadius_ = 0.;
- return;
- }
-
- // Central angle
- double _nCentralAngle = atan(nBulge_) * 4.0;
- ASSERT(DOUBLE_NOT_ZERO(_nCentralAngle));
-
- // 1) Radius
- double _nRadius = _nChordLen * 0.5 / sin(_nCentralAngle * 0.5);
- nRadius_ = fabs(_nRadius);
-
- // 2) Center
- // 2-1) proportional translate
- double _nAlpha = _nRadius / _nChordLen;
-
- DPOINT2 _nxByPropTrans;
- _nxByPropTrans.x = _nxFromTo.x * _nAlpha;
- _nxByPropTrans.y = _nxFromTo.y * _nAlpha;
-
- // 2-2) revolving transform
- double _nTheta = (c_nPIE - _nCentralAngle) * 0.5;
- DPOINT2 _nxByRevTrans;
- _nxByRevTrans.x = cos(_nTheta) * _nxByPropTrans.x - sin(_nTheta) * _nxByPropTrans.y;
- _nxByRevTrans.y = sin(_nTheta) * _nxByPropTrans.x + cos(_nTheta) * _nxByPropTrans.y;
-
- // 2-3) Get circle center
- nxCenter_.x = nxStart_.x + _nxByRevTrans.x;
- nxCenter_.y = nxStart_.y + _nxByRevTrans.y;
-
- // 3) Start angle
- nStartAngle_ = _compute_angle(nxStart_.x - nxCenter_.x, nxStart_.y - nxCenter_.y);
-
- // 4) End angle
- nEndAngle_ = nStartAngle_ + _nCentralAngle;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // class CNceParser
- //////////////////////////////////////////////////////////////////////////
- CNceParser::CNceParser(CParserModule* pParserModule_, const CCodeBuffer* pCodeBuffer_)
- : CCodeParser(pParserModule_, pCodeBuffer_)
- , m_pCamObject(NULL)
- , m_bIsFisrtValidMotion(false)
- , m_bPrePostActionValid(false)
- , m_bPrelude(true)
- , m_pCamWrapperSearcher(NULL)
- , m_nSystemMaxSpeed(c_nINVALID_DOUBLE)
- , m_bEnableSlowlyStart(false)
- , m_nSlowlyStartSumLen(0.)
- , m_bScanPath(false)
- , m_bMergeable(true)
- {
- m_pCamObject = reinterpret_cast<const nce::CCamGroup*>(pCodeBuffer_->GetDataBuffer());
- m_pCamParams = reinterpret_cast<const nce::ParamVector*>(pCodeBuffer_->GetCamParams());
- Reset();
- }
-
- CNceParser::~CNceParser()
- {
- m_pCamObject = NULL;
- if (NULL != m_pCamWrapperSearcher)
- {
- delete m_pCamWrapperSearcher;
- m_pCamWrapperSearcher = NULL;
- }
-
- while (m_listPreAction.GetCount())
- {
- delete m_listPreAction.RemoveHead();
- }
-
- while (m_listPostAction.GetCount())
- {
- delete m_listPostAction.RemoveHead();
- }
- }
-
- //////////////////////////////////////////////////////////////////////////
- // public function
- void CNceParser::ReadCode()
- {
- if (m_pCamObject == NULL || m_nStartID == 0 || m_nEndID == 0)
- {
- ASSERT(false);
- // 强制写加工范围为已完成,此时起始位置与终止位置相同,需多次调整文件位置到完成。
- m_nCurPosToField = FP_RIGHT;
- return;
- }
-
- try
- {
- const_CamObjCollector _pCamObj = m_pCamWrapperSearcher->GetNextCamObj();
- if (_pCamObj != NULL)
- AnalyseObject(_pCamObj);
- else
- {
- // 如果未找到Cam对象,则抛出提示信息,并停止解析 ---- duquan 2017-07-10
- // 附:这里只是防止Nce解析死循环,出现这种情况一般是外部传入的加工数据和加工范围不一致
- NcInterpAxes3::ShowMessage(c_szERROR_CAMDADTAOUTRANGE);
- throw(CForceStop());
- }
- }
- catch (CPause)
- {
- m_bAnalyse = false;
- m_nStartID = m_nEntityID;
- }
- }
-
- void CNceParser::Reset()
- {
- m_nEntityID = 0;
- m_nIndexOff = 0;
- m_nStartID = 0;
- m_nEndID = 0;
- m_bAnalyse = false;
- __super::Reset();
-
- m_bPrelude = true;
- reset_ParseParam(m_pInterpEngine);
- }
-
- bool CNceParser::Eof()
- {
- // 不通过超出区间来超越文件尾,让调试去尝试到没有区间或加工再结束 ---- 杨开锦 2012-05-14
- return false;
- }
-
- __int64 CNceParser::GetPosition() const
- {
- NceFilePos _NcePos;
- GetNceFilePos(m_nEntityID, m_nIndexOff, 0., _NcePos);
-
- return __int64(_NcePos)/*MAKE_NCE_POS(m_nEntityID, m_nIndexOff)*/;
- }
-
- void CNceParser::SetPosition(__int64 nPos_)
- {
- NceFilePos _NcePos;
- _NcePos = nPos_;
-
- m_nEntityID = _NcePos.GetID()/*GET_ID_FROM_NCEPOS(nPos_)*/;
- m_nIndexOff = _NcePos.GetOffset()/*GET_OFFSET_FROM_NCEPOS(nPos_)*/;
- }
-
- CCodeParser::fieldpos_t CNceParser::GetCurPosField()
- {
- // 只使用ID和OFFSET作为比较范围,因为每段NcCode取出来的文件位置的Rate值均为0
- // lingshu 20120226
- NceFilePos _nCurFieldTo, _nCurFieldFrom;
- GetNceFilePos(m_CurField.idoff_to.nID, m_CurField.idoff_to.nOffset, 0., _nCurFieldTo);
- GetNceFilePos(m_CurField.idoff_from.nID, m_CurField.idoff_from.nOffset, 0., _nCurFieldFrom);
-
- __int64 _nPos = GetPosition();
- if (_nPos == _nCurFieldTo)
- {
- // 当from == to时
- ASSERT(m_nCurPosToField == FP_LEFT || m_nCurPosToField == FP_START || m_nCurPosToField == FP_END);
- m_nCurPosToField = FP_END;
- }
- else if (_nPos == _nCurFieldFrom)
- {
- ASSERT(m_nCurPosToField == FP_LEFT || m_nCurPosToField == FP_START);
- m_nCurPosToField = FP_START;
- }
- else
- {
- if (m_nCurPosToField == FP_END)
- m_nCurPosToField = FP_RIGHT;
- }
-
- return m_nCurPosToField;
- }
-
- void CNceParser::SetField(const LCRO_FIELD& Field_)
- {
- __super::SetField(Field_);
- m_nStartID = Field_.idoff_from.nID;
- m_nEndID = Field_.idoff_to.nID;
- m_pParserModule->m_bIsJumping = true;
-
- // 到来一个新区间,首跳与首PreAction要重置 ---- 杨开锦 2012-05-14
- m_bIsFisrtValidMotion = false;
- m_bPrePostActionValid = false;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // protected function
- void CNceParser::AnalyseGroup(const nce::CCamGroup* pGroup_)
- {
- if (NULL == pGroup_)
- {
- ASSERT(false);
- return;
- }
-
- camwrapper::CCamGroupWrapper _CamGroupWrapper(pGroup_);
- for (int i = 0, _nCount = _CamGroupWrapper.GetCount(); i < _nCount; ++i)
- {
- const nce::CCamObject* _pObject = _CamGroupWrapper.GetAt(i);
- AnalyseObject(_pObject);
- }
- }
-
- void CNceParser::AnalyseObject(const nce::CCamObject* pObject_)
- {
- if (NULL == pObject_)
- {
- ASSERT(false);
- return;
- }
-
- ResetSlowStartInfo();
-
- switch (pObject_->GetType())
- {
- case nce::camhole:
- AnalyseHole(reinterpret_cast<const nce::CCamHole*>(pObject_));
- break;
-
- case nce::campath:
- AnalysePath(reinterpret_cast<const nce::CCamPath*>(pObject_));
- break;
-
- // 不必遍历组内成员,由外部的Searcher负责遍历 lingshu 20120605
- case nce::camgroup:
- //_AnalyseGroup(reinterpret_cast<const nce::CCamGroup*>(pObject_));
- break;
-
- case nce::camscanlines:
- default:
- ASSERT(false);
- break;
- }
- }
-
- void CNceParser::AnalysePath(const nce::CCamPath* pPath_)
- {
- if (NULL == pPath_)
- {
- ASSERT(false);
- return;
- }
-
- ASSERT(m_pParserModule->m_CodePosition.nAnchorType == ANCH_IDOFFSET);
- if (!CheckStartField(pPath_->GetID()))
- return;
-
- // 区分是否是扫描切割:扫描切割前会将段数及各段的起点偏移以非字符串形式发送
- m_bScanPath = IsScanCutPath(pPath_);
-
- // 用于补偿偏心导致的过棱长度
- bool _bEnable = static_cast<bool>(m_pParserModule->GetNamedVariable("#NceExtParam1_OverEdgeOffsetEnable"));
- nce::CParam* _pParamForMidXOffset = GetAt_ParamVector(m_pCamParams, pPath_->GetParamIndex());
- if (_bEnable)
- {
- m_pParserModule->m_pOverEdgeAdjust->SetOverEdgeInfo(pPath_, _pParamForMidXOffset);
- }
- // 使用CCamSplineWrapper(其中支持巡边)对样条的几何信息进行访问 ---- 杨开锦 2015-08-25
- camwrapper::CCamSplineWrapper _CamSplineWrapper(pPath_, m_pParserModule->m_pWCSAdjust);
- camwrapper::CCamPathWrapper _CamPathWrapper(pPath_, m_pParserModule->m_pWCSAdjust, m_pParserModule->m_pAngleToArc, m_pParserModule->m_pOverEdgeAdjust, _bEnable);
- nce::CParam* _pParam = BeforeAnalysePath(pPath_, &_CamSplineWrapper, _CamPathWrapper.GetStartPoint());
-
- VECINT _vecScanGXXIndex;
- StopCornerInfo _StopCornerInfo;
- if (m_bScanPath)
- {
- // 扫描切割:
- // 1.没有角点停顿
- // 2.没有慢速起步
- // 3.圆扫描时标识可以单轴联动的空程
- GetScanGXXIndex(pPath_, _vecScanGXXIndex);
- }
- else
- {
- // 获取角点停顿信息
- GetStopCornerInfo(pPath_, _pParam, _StopCornerInfo);
- // 初始化慢速起步信息
- InitSlowStartInfo();
- }
-
- // 区分是否包含样条:包含样条的路径从字符串中解析加工数据
- if (_CamSplineWrapper.IsSpline())
- {
- // 只支持XY平面上的图形
- AnalyseNurbsPath(pPath_, &_CamSplineWrapper, _vecScanGXXIndex, _StopCornerInfo);
- }
- else
- {
- AnalyseNormalPath(pPath_, &_CamPathWrapper, _vecScanGXXIndex, _StopCornerInfo);
- }
-
- ResetSlowStartInfo();
- AfterAnalysePath(pPath_, _StopCornerInfo);
- }
-
- void CNceParser::SendCamObjStartRateCode()
- {
- // ForwardParser
- CNcSendRawInt _NcRawInt(m_pParserModule->m_CodePosition);
- short _nRatio = 0;
- _NcRawInt.m_nInteger = MAKELONG(_nRatio, RIH_BROKEN_RATIO);
- AddTailCode(_NcRawInt);
- }
-
- void CNceParser::SendCamObjEndRateCode()
- {
- // ForwardParser
- CNcSendRawInt _NcRawInt(m_pParserModule->m_CodePosition);
- #define RATIO_MULTIPLE 10000
- short _nRatio = RATIO_MULTIPLE;
- #undef RATIO_MULTIPLE
- _NcRawInt.m_nInteger = MAKELONG(_nRatio, RIH_BROKEN_RATIO);
- AddTailCode(_NcRawInt);
- }
-
- double CNceParser::GetMaxSpeedFromPathParam()
- {
- double _nMaxSpeed = m_pParserModule->m_nSpeedGxx;
-
- if (m_pParserModule->m_nAssignSpeedType == CGCodeMeaning::AS_FILE)
- {
- if (m_ParamPath.m_FeedRate.IsValid() && DOUBLE_NOT_ZERO(m_ParamPath.m_FeedRate.m_nValue))
- {
- _nMaxSpeed = m_ParamPath.m_FeedRate.m_nValue;
- __CUT(_nMaxSpeed, 0, m_pParserModule->m_nSpeedG00);
- }
- }
-
- return _nMaxSpeed;
- }
-
- void CNceParser::GetSlowlyStartParam(const nce::CParam* pParam_)
- {
- ASSERT(pParam_ != NULL);
-
- // 获取慢速起步图层参数
- m_SlowlyStartLayerParam = SlowlyStartLayerParam();
- if (pParam_->GetKey_DBL("SlowlyStartup") == 1)
- {
- m_SlowlyStartLayerParam.m_bSlowlyStart = true;
- m_SlowlyStartLayerParam.m_nSlowlyStartLen = pParam_->GetKey_DBL("SlowlyStartupDis");
- m_SlowlyStartLayerParam.m_nSlowlyStartSpeed = pParam_->GetKey_DBL("SlowlyStartupSpeed") / 60.0;
- ASSERT(m_SlowlyStartLayerParam.m_nSlowlyStartLen >= 0.);
- ASSERT(m_SlowlyStartLayerParam.m_nSlowlyStartSpeed >= 0.);
- }
- }
-
- void CNceParser::GetPathMergeableParam(const nce::CCamPath* pPath_)
- {
- ASSERT(pPath_ != NULL);
-
- // 获取Path中的运动指令是否可合并
- m_bMergeable = (pPath_->GetKey("MergeNodes").Compare("Disable") == 0) ? false : true;
- }
-
- void CNceParser::GetOverArrisSpeedParam(const nce::CParam* pParam_)
- {
- ASSERT(pParam_ != NULL);
-
- // 仅当加工方管时,才获取过棱速度 ---- duquan 2017-05-07
- CStringA _strTubeParam = pParam_->GetKey("TubeParam");
- if (_strTubeParam.IsEmpty())
- {
- ASSERT(IsInvalidDouble(m_pParserModule->m_nOverArrisSpeed));
- return;
- }
-
- ASSERT((_strTubeParam.GetLength() > 2) && (_strTubeParam.Left(1) == "\"") && (_strTubeParam.Right(1) == "\""));
- _strTubeParam = _strTubeParam.Mid(1, _strTubeParam.GetLength() - 2);
- ASSERT(_strTubeParam.FindOneOf("=;\"") == -1);
- _strTubeParam.Replace('@', '=');
- _strTubeParam.Replace('$', ';');
-
- CStringA _strType = pParam_->GetKey_FromString(_strTubeParam, "Type");
- ASSERT(!_strType.IsEmpty());
-
- // 暂时只支持这几种管材:0为圆管,1为方管,2为椭圆管,3为腰形管
- int _nType = atoi(_strType);
- ASSERT((_nType >= 0) && (_nType <= 3));
- if (_nType != 1)
- {
- m_pParserModule->m_nOverArrisSpeed = c_nINVALID_DOUBLE;
- return;
- }
-
- // 把图层的过棱速度由角度转换成弧度 ---- DingQiang 2016-08-25
- if (!pParam_->GetKey("OverArrisSpeed").IsEmpty())
- {
- double _nOverArrisSpeed = pParam_->GetKey_DBL("OverArrisSpeed");
- ASSERT(DOUBLE_GREAT_ZERO(_nOverArrisSpeed));
- ASSERT(m_pParserModule->m_pAngleToArc != NULL);
- m_pParserModule->m_nOverArrisSpeed = m_pParserModule->m_pAngleToArc->AngleToArc(_nOverArrisSpeed, axis::z) / 60.0;
-
- // 限制过棱速度不大于旋转轴空程速度 ---- duquan 2016.12.07
- if (m_pParserModule->m_nOverArrisSpeed > m_pParserModule->m_nSpeedG00Rev)
- m_pParserModule->m_nOverArrisSpeed = m_pParserModule->m_nSpeedG00Rev;
- }
- }
-
- void CNceParser::RetrieveRespPos(const DPOINT3& nxPosBefore_, INTERPDOUBLE* pnxPosAfter_)
- {
- (*pnxPosAfter_)[NcInterpAxes3::axis::x] = m_pParserModule->WorkCoorToMachineCoor(nxPosBefore_.x, NcInterpAxes3::axis::x);
- (*pnxPosAfter_)[NcInterpAxes3::axis::y] = m_pParserModule->WorkCoorToMachineCoor(nxPosBefore_.y, NcInterpAxes3::axis::y);
- (*pnxPosAfter_)[NcInterpAxes3::axis::z] = m_pParserModule->WorkCoorToMachineCoor(nxPosBefore_.z, NcInterpAxes3::axis::z);
- }
-
- void CNceParser::GotoHeadPos(const INTERPDOUBLE& nxDestPos_)
- {
- INTERPDOUBLE _nxCurPos = m_pParserModule->m_nxJumpPos;
-
- // 加载轨迹时当前点无效
- if (IsInvalidDouble(_nxCurPos[axis::x]) || IsInvalidDouble(_nxCurPos[axis::y]) || IsInvalidDouble(_nxCurPos[axis::z]))
- return;
-
- double _nLen = (nxDestPos_ - _nxCurPos).GetLength();
- if (DOUBLE_EQU_ZERO(_nLen))
- return;
-
- MoveToDestPos(nxDestPos_);
- }
-
- void CNceParser::UpdateCurrentPos(int nID_, int nOffset_)
- {
- m_pParserModule->m_CodePosition.nID = m_nEntityID = nID_;
- m_pParserModule->m_CodePosition.nOffset = m_nIndexOff = nOffset_;
- }
-
- bool CNceParser::CheckStartField(int nID_)
- {
- if (m_bAnalyse)
- UpdateCurrentPos(nID_, -1);
- else if (m_nStartID == nID_)
- {
- m_bAnalyse = true;
- UpdateCurrentPos(nID_, -1);
- }
-
- return m_bAnalyse;
- }
-
- void CNceParser::CheckEndField(int nID_)
- {
- UpdateCurrentPos(nID_, -1); // 用于更新文件位置,更新Field标志
- GetCurPosField();
- if (m_bAnalyse && (m_nEndID == m_nEntityID))
- throw(CPause());
- }
-
- void CNceParser::GenerateNode(const spline::SplineVector& vectorSplines_, int nNurbsIndex_, int nPointIndex_, nce::CCamPath::NODE& node_)
- {
- if (DOUBLE_EQU_ZERO(vectorSplines_[nNurbsIndex_].vecControlPoint[nPointIndex_].nBulge))
- {
- ASSERT(0.0 == vectorSplines_[nNurbsIndex_].vecControlPoint[nPointIndex_].nBulge);
- node_.nType = nce::CCamPath::nt_line_xy;
- node_.nBulge = 0.;
- }
- else
- {
- node_.nType = nce::CCamPath::nt_arc_xy;
- node_.nBulge = vectorSplines_[nNurbsIndex_].vecControlPoint[nPointIndex_].nBulge;
- }
-
- node_.ptStart = DPOINT3(vectorSplines_[nNurbsIndex_].vecControlPoint[nPointIndex_ - 1].nEndX,
- vectorSplines_[nNurbsIndex_].vecControlPoint[nPointIndex_ - 1].nEndY,
- 0.);
- node_.ptEnd = DPOINT3(vectorSplines_[nNurbsIndex_].vecControlPoint[nPointIndex_].nEndX,
- vectorSplines_[nNurbsIndex_].vecControlPoint[nPointIndex_].nEndY,
- 0.);
- }
-
- void CNceParser::GenerateNurbsNode(const spline::SplineVector& vectorSplines_, int nNurbsIndex_, NurbsInfo& NurbsInfo_)
- {
- // NURBS曲线的幂次
- NurbsInfo_.nLevel = 3;
-
- // NURBS曲线的节点矢量
- int _nKnotNum = vectorSplines_[nNurbsIndex_].vecKnot.size();
- NurbsInfo_.vecKnot.clear();
- NurbsInfo_.vecKnot.reserve(_nKnotNum);
- for (int i = 0; i < _nKnotNum; ++i)
- NurbsInfo_.vecKnot.push_back(vectorSplines_[nNurbsIndex_].vecKnot[i]);
-
- // NURBS曲线的控制点
- int _nPointNum = vectorSplines_[nNurbsIndex_].vecControlPoint.size();
- NurbsInfo_.vecControlPoint.clear();
- NurbsInfo_.vecControlPoint.reserve(_nPointNum);
- for (int i = 0; i < _nPointNum; ++i)
- {
- NurbsInfo_.vecControlPoint.push_back(INTERPDOUBLE(vectorSplines_[nNurbsIndex_].vecControlPoint[i].nEndX,
- vectorSplines_[nNurbsIndex_].vecControlPoint[i].nEndY, 0.));
- }
-
- // NURBS曲线控制点的权值
- NurbsInfo_.vecWeight.clear();
- NurbsInfo_.vecWeight.reserve(_nPointNum);
- int _nWeightNum = vectorSplines_[nNurbsIndex_].vecWeight.size();
- for (int i = 0; i < _nWeightNum; ++i)
- NurbsInfo_.vecWeight.push_back(vectorSplines_[nNurbsIndex_].vecWeight[i]);
- }
-
- void CNceParser::GenerateSpindleRevCode()
- {
- if (m_pParserModule->m_bIgnoreProgSpindleRev)
- return;
-
- int _nSpindleRev = 0;
- if (RetrieveSpindleRevFromPathParam(&_nSpindleRev))
- {
- CNcChangSpindleRev _NcChangSpindleRev(m_pParserModule->m_CodePosition);
- _NcChangSpindleRev.m_nSpindleRev = _nSpindleRev;
- _NcChangSpindleRev.m_nType = 0;
- AddTailCode(_NcChangSpindleRev);
- }
- }
-
- void CNceParser::MotionCodeByNodeType(const nce::CCamPath::NODE& node_, const ScanCutInfo& ScanCutInfo_)
- {
- switch (node_.nType)
- {
- case nce::CCamPath::nt_line_x:
- case nce::CCamPath::nt_line_y:
- case nce::CCamPath::nt_line_z:
- case nce::CCamPath::nt_line_xy:
- case nce::CCamPath::nt_line_yz:
- case nce::CCamPath::nt_line_zx:
- case nce::CCamPath::nt_line_xyz:
- LineCode(node_, ScanCutInfo_);
- break;
-
- case nce::CCamPath::nt_arc_xy:
- case nce::CCamPath::nt_arc_yz:
- case nce::CCamPath::nt_arc_zx:
- ArcCode(node_, ScanCutInfo_);
- break;
-
- case nce::CCamPath::nt_circle_xy_cw:
- case nce::CCamPath::nt_circle_xy_ccw:
- case nce::CCamPath::nt_circle_yz_cw:
- case nce::CCamPath::nt_circle_yz_ccw:
- case nce::CCamPath::nt_circle_zx_cw:
- case nce::CCamPath::nt_circle_zx_ccw:
- CircleCode(node_, ScanCutInfo_);
- break;
-
- default:
- ASSERT(false);
- break;
- }
- }
-
- void CNceParser::LineCode(const nce::CCamPath::NODE& node_, const ScanCutInfo& ScanCutInfo_)
- {
- ASSERT((node_.nType & nce::CCamPath::nt_line) == nce::CCamPath::nt_line);
- ASSERT(node_.nBulge == 0.);
-
- CNcLine _NcLine(NCFGLINEARINTERP, m_nSystemMaxSpeed, m_pParserModule->m_CodePosition);
- _NcLine.m_bIsScanCut = ScanCutInfo_.bIsScanCut;
- _NcLine.m_bIsArcScanG0 = ScanCutInfo_.bIsArcScanCutG0;
- _NcLine.m_nRadialRadius = ScanCutInfo_.nRadialRadius;
- _NcLine.m_bIsMergeable = m_bMergeable;
- if (_NcLine.m_bIsArcScanG0)
- _NcLine.m_nPlane = ScanCutInfo_.nPlane;
-
- // 反向解析调整起始终止比率 lingshu 20120222
- if (Reverse_Parse == GetParserDir())
- _NcLine.SetReverseMotion();
-
- // 起点和终点
- INTERPDOUBLE _nxStart;
- INTERPDOUBLE _nxEnd;
- RetrieveRespPos(node_.ptStart, &_nxStart);
- RetrieveRespPos(node_.ptEnd, &_nxEnd);
- _NcLine.OrigSetStartPos(_nxStart);
- _NcLine.OrigSetEndPos(_nxEnd);
-
- CheckWCSLimit(_nxStart, _nxEnd);
- ModifyMotionCodeRate(&_NcLine);
- SplitMotionBySlowStart(_NcLine);
- }
-
- void CNceParser::ArcCode(const nce::CCamPath::NODE& node_, const ScanCutInfo& ScanCutInfo_)
- {
- ASSERT((node_.nType & nce::CCamPath::nt_arc) == nce::CCamPath::nt_arc);
- ASSERT(DOUBLE_NOT_ZERO(node_.nBulge));
-
- NC_FUNCTION_TAG _tag = node_.nBulge < 0 ? NCFGARCINTERPCW : NCFGARCINTERPCCW;
- CNcArc _NcArc(_tag, m_nSystemMaxSpeed, m_pParserModule->m_CodePosition);
- _NcArc.m_nSpiralPitch = 0.;
- _NcArc.m_bIsScanCut = ScanCutInfo_.bIsScanCut;
- _NcArc.m_bIsMergeable = m_bMergeable;
-
- // 反向解析调整起始终止比率 lingshu 20120222
- if (Reverse_Parse == GetParserDir())
- _NcArc.SetReverseMotion();
-
- // 坐标平面
- GetArcPlane(node_, &_NcArc);
-
- // 起点和终点
- INTERPDOUBLE _nxStart;
- INTERPDOUBLE _nxEnd;
- RetrieveRespPos(node_.ptStart, &_nxStart);
- RetrieveRespPos(node_.ptEnd, &_nxEnd);
- _NcArc.OrigSetStartPos(_nxStart);
- _NcArc.OrigSetEndPos(_nxEnd);
- ASSERT(_nxStart[_NcArc.m_nPlane.GetThirdAxis()] == _nxEnd[_NcArc.m_nPlane.GetThirdAxis()]);
-
- // 圆心与起始角、终止角
- int _nAxisX = _NcArc.m_nPlane.GetLeftAxis();
- int _nAxisY = _NcArc.m_nPlane.GetRightAxis();
- DPOINT2 _ptStart(node_.ptStart[_nAxisX], node_.ptStart[_nAxisY]);
- DPOINT2 _ptEnd(node_.ptEnd[_nAxisX], node_.ptEnd[_nAxisY]);
- DPOINT2 _ptCenter2;
- double _nAngleStart = 0.;
- double _nAngleEnd = 0.;
- double _nRadius = 0.;
- RetrieveArcInf(_ptStart, _ptEnd, node_.nBulge, _ptCenter2, _nAngleStart, _nAngleEnd, _nRadius);
-
- // 检查是否为微小的圆弧,如果是,当作直线处理 ---- duquan 2017-03-29
- // 原因:防止圆弧在修正角度时将微小的劣弧修正为较大的优弧
- if (CheckTinyArc(fabs(_nAngleEnd - _nAngleStart), _nRadius))
- {
- nce::CCamPath::NODE _lineNode;
- _lineNode.nType = nce::CCamPath::nt_line;
- _lineNode.nBulge = 0.;
- _lineNode.ptStart = node_.ptStart;
- _lineNode.ptEnd = node_.ptEnd;
- LineCode(_lineNode, ScanCutInfo_);
- return;
- }
-
- DPOINT3 _ptCenter;
- _ptCenter[_nAxisX] = _ptCenter2.x;
- _ptCenter[_nAxisY] = _ptCenter2.y;
- _ptCenter[_NcArc.m_nPlane.GetThirdAxis()] = _nxStart[_NcArc.m_nPlane.GetThirdAxis()];
- INTERPDOUBLE _nxCenter;
- RetrieveRespPos(_ptCenter, &_nxCenter);
- _NcArc.SetCenterPos(_nxCenter);
-
- _NcArc.OrigSetStartAngle(_nAngleStart);
- _NcArc.OrigSetEndAngle(_nAngleEnd);
- _NcArc.SetRadius(_nRadius);
- _NcArc.ReviseAngle();
-
- CheckWCSLimitForArc(&_NcArc);
- ModifyMotionCodeRate(&_NcArc);
- SplitMotionBySlowStart(_NcArc);
- }
-
- void CNceParser::CircleCode(const nce::CCamPath::NODE& node_, const ScanCutInfo& ScanCutInfo_)
- {
- ASSERT((node_.nType & nce::CCamPath::nt_circle) == nce::CCamPath::nt_circle);
-
- CNcArc _NcArc(NCFGARCINTERPCCW, m_nSystemMaxSpeed, m_pParserModule->m_CodePosition);
- _NcArc.m_nSpiralPitch = 0.;
- _NcArc.m_bIsScanCut = ScanCutInfo_.bIsScanCut;
- _NcArc.m_bIsMergeable = m_bMergeable;
-
- // 反向解析调整起始终止比率 lingshu 20120222
- if (Reverse_Parse == GetParserDir())
- _NcArc.SetReverseMotion();
-
- // 平面及方向
- GetCirclePlaneAndDirectory(node_, &_NcArc);
-
- // 起始点、终止点
- INTERPDOUBLE _nxStart;
- RetrieveRespPos(node_.ptStart, &_nxStart);
- _NcArc.OrigSetStartPos(_nxStart);
- _NcArc.OrigSetEndPos(_nxStart);
-
- // 圆心
- DPOINT3 _ptCenter = node_.ptCenter;
- INTERPDOUBLE _nxCenter;
- RetrieveRespPos(_ptCenter, &_nxCenter);
- _NcArc.SetCenterPos(_nxCenter);
-
- // 起始角和终止角
- _NcArc.SetRadius(node_.nRadius);
- _NcArc.ReviseShape();
-
- CheckWCSLimitForArc(&_NcArc);
- ModifyMotionCodeRate(&_NcArc);
- SplitMotionBySlowStart(_NcArc);
- }
-
- void CNceParser::NurbsCode(NurbsInfo& NurbsInfo_, const ScanCutInfo& ScanCutInfo_)
- {
- ASSERT(!NurbsInfo_.vecKnot.empty() && !NurbsInfo_.vecControlPoint.empty());
- ASSERT(NurbsInfo_.vecWeight.empty() || (NurbsInfo_.vecWeight.size() == NurbsInfo_.vecControlPoint.size()));
- ASSERT(NurbsInfo_.vecKnot.size() == NurbsInfo_.nLevel + NurbsInfo_.vecControlPoint.size() + 1);
-
- // 将控制点坐标转换为机械坐标
- int _nPointNum = NurbsInfo_.vecControlPoint.size();
- for (int i = 0; i < _nPointNum; ++i)
- {
- DPOINT3 _nxTempPoint(NurbsInfo_.vecControlPoint[i][axis::x], NurbsInfo_.vecControlPoint[i][axis::y], NurbsInfo_.vecControlPoint[i][axis::z]);
- RetrieveRespPos(_nxTempPoint, &NurbsInfo_.vecControlPoint[i]);
- }
-
- CNcNurbs _NcNurbs(NCFGNURBS, m_nSystemMaxSpeed, m_pParserModule->m_CodePosition);
- _NcNurbs.m_bIsScanCut = ScanCutInfo_.bIsScanCut;
- _NcNurbs.m_bIsMergeable = m_bMergeable;
- _NcNurbs.SetLevel(NurbsInfo_.nLevel);
- _NcNurbs.SetKnots(NurbsInfo_.vecKnot);
- _NcNurbs.SetControlPoints(NurbsInfo_.vecControlPoint);
- _NcNurbs.SetWeights(NurbsInfo_.vecWeight);
-
- // 反向解析调整起始终止比率
- if (Reverse_Parse == GetParserDir())
- _NcNurbs.SetReverseMotion();
-
- // 起点和终点
- _NcNurbs.OrigSetStartPos(NurbsInfo_.vecControlPoint.front());
- _NcNurbs.OrigSetEndPos(NurbsInfo_.vecControlPoint.back());
-
- CheckWCSLimitForNurbs(NurbsInfo_.vecControlPoint);
- ModifyMotionCodeRate(&_NcNurbs);
-
- // NURBS曲线:设置参数
- _NcNurbs.SetInterpPeriod(m_pInterpEngine->m_pInterpData->m_nT);
- _NcNurbs.SetNurbsParams();
-
- SplitMotionBySlowStart(_NcNurbs);
- }
-
- void CNceParser::AddTailCode(CNcCode& NcCode_, bool bIgnoreFP_)
- {
- bool _bMotionCode = NcCode_.IsMotion();
- CCodeParser::fieldpos_t _fp = GetCurPosField();
- if (!(_fp & CCodeParser::FP_MIDDLE) && !bIgnoreFP_)
- {
- if (_bMotionCode)
- m_pParserModule->m_nxJumpPos = ((CNcMotion&)NcCode_).MachGetEndPos();
- return;
- }
-
- // 非运动指令允许加入队列?临时处理,防止添加速度指令时修改了m_bIsJumping的值,从而导致不能正确插入
- // 首条跳转指令 lingshu 20120226
- if (m_pParserModule->m_bIsJumping)
- {
- if (NcCode_.m_nFunTag == NCFGRAPIDTRAVERSE)
- return;
- m_pParserModule->m_bIsJumping = false;
- }
-
- while (true)
- {
- if (m_bIsFisrtValidMotion)
- break;
-
- // 第一次遇到有效运动指令时,应做的一些处理 lingshu 20120319
- if (m_pParserModule->m_bIsJumping || !_bMotionCode)
- break;
-
- m_bIsFisrtValidMotion = true;
-
- // 在整个加工开始的时候,将起始文件范围发送出去,修正记录值 lingshu 20120301
- if (!m_pInterpEngine->IsTracking())
- {
- CFilePosition _startFP;
- _startFP.nAnchorType = ANCH_IDOFFSET;
- _startFP.nID = m_pInterpEngine->m_FieldList.GetHead().idoff_from.nID;
- _startFP.nOffset = m_pInterpEngine->m_FieldList.GetHead().idoff_from.nOffset;
- _startFP.nRate = m_pInterpEngine->m_FieldList.GetHead().idoff_from.nRate;
-
- CNcFilePosition _NcFilePos(NCFCFILEPOSITION, _startFP);
- m_pParserModule->AddTailCode(_NcFilePos);
- }
-
- if (_bMotionCode)
- m_pParserModule->m_nxJumpPos = ((CNcMotion&)NcCode_).MachGetStartPos();
-
- if (!m_pInterpEngine->IsTracking())
- {
- m_pParserModule->InsertSafeJumpInstruction();
- if (m_bPrelude)
- {
- m_pParserModule->InsertPreludeCode();
- m_bPrelude = false;
- }
-
- // 第一次进入有效指令时,强行插入preCode
- InsertPreActionCode(true);
- }
-
- break;
- }
-
- if (_bMotionCode)
- m_pParserModule->m_nxJumpPos = ((CNcMotion&)NcCode_).MachGetEndPos();
-
- m_pParserModule->AddTailCode(NcCode_);
- }
-
- bool CNceParser::IsScanCutPath(const nce::CCamPath* pPath_) const
- {
- return !(pPath_->GetKey(c_szScanGxxNodes).IsEmpty());
- }
-
- void CNceParser::GetScanGXXIndex(const nce::CCamPath* pPath_, VECINT& vecGXXIndex_)
- {
- vecGXXIndex_.clear();
-
- CStringA _strScanFlag = pPath_->GetKey(c_szScanGxxNodes);
- if (_strScanFlag.IsEmpty())
- return;
-
- // 解析GXX对应的索引集
- int _nLength = _strScanFlag.GetLength();
- vecGXXIndex_.reserve(_nLength >> 1);
-
- int _nStartIndex = 0;
- for (int i = 0; i < _nLength; ++i)
- {
- if (_strScanFlag[i] != ',')
- continue;
-
- CStringA _strSubString = _strScanFlag.Mid(_nStartIndex, i - _nStartIndex);
- if (_strSubString.IsEmpty())
- continue;
-
- vecGXXIndex_.push_back(atoi(_strSubString));
- _nStartIndex = i + 1;
- }
- }
-
- void CNceParser::GetNurbsScanCutInfo(const VECINT& vecGXXIndex_, ScanCutInfo& ScanCutInfo_)
- {
- ASSERT(m_bScanPath == !vecGXXIndex_.empty());
- if (vecGXXIndex_.empty())
- return;
-
- // 扫描切割
- ScanCutInfo_.bIsScanCut = true;
- }
-
- void CNceParser::GetScanCutInfo(const camwrapper::CCamPathWrapper* pCamPathWrapper_,
- const VECINT& vecGXXIndex_,
- int nCurIndex_,
- ScanCutInfo& ScanCutInfo_)
- {
- ASSERT(m_bScanPath == !vecGXXIndex_.empty());
-
- if (vecGXXIndex_.empty())
- return;
-
- // 扫描切割
- ScanCutInfo_.bIsScanCut = true;
-
- VECINT::const_iterator _iter = find(vecGXXIndex_.begin(), vecGXXIndex_.end(), nCurIndex_);
- if (_iter != vecGXXIndex_.end())
- return;
-
- if ((0 == nCurIndex_) || (pCamPathWrapper_->GetNodeCount() == nCurIndex_ + 1))
- return;
-
- nce::CCamPath::NODE _preNode = pCamPathWrapper_->GetNode(nCurIndex_ - 1);
- nce::CCamPath::NODE _curNode = pCamPathWrapper_->GetNode(nCurIndex_);
- nce::CCamPath::NODE _nextNode = pCamPathWrapper_->GetNode(nCurIndex_ + 1);
-
- GetScanCutInfo(_preNode, _curNode, _nextNode, ScanCutInfo_);
- }
-
- void CNceParser::GetScanCutInfo(const camwrapper::CCamSplineWrapper* pCamSplineWrapper_,
- const VECINT& vecGXXIndex_,
- const nce::CCamPath::NODE& curNode_,
- int nNurbsIndex_,
- int nPointIndex_,
- int nCurIndex_,
- ScanCutInfo& ScanCutInfo_)
- {
- ASSERT(m_bScanPath == !vecGXXIndex_.empty());
-
- if (vecGXXIndex_.empty())
- return;
-
- // 扫描切割
- ScanCutInfo_.bIsScanCut = true;
-
- VECINT::const_iterator _iter = find(vecGXXIndex_.begin(), vecGXXIndex_.end(), nCurIndex_);
- if (_iter != vecGXXIndex_.end())
- return;
-
- const spline::SplineVector _vecSplines = pCamSplineWrapper_->GetSplines();
- const int _nNodeCount = pCamSplineWrapper_->GetSegmentCount();
- if ((nNurbsIndex_ == 0 && nPointIndex_ == 1)
- || (nNurbsIndex_ == _vecSplines.size() - 1 && nPointIndex_ == _vecSplines[nNurbsIndex_].vecControlPoint.size() - 1))
- return;
-
- // 检查上一个节点
- nce::CCamPath::NODE _preNode;
- if (nPointIndex_ > 1)
- {
- GenerateNode(_vecSplines, nNurbsIndex_, nPointIndex_ - 1, _preNode);
- }
- else
- {
- ASSERT(nNurbsIndex_ > 0);
- if (!_vecSplines[nNurbsIndex_ - 1].vecKnot.empty())
- return;
-
- GenerateNode(_vecSplines, nNurbsIndex_ - 1, _vecSplines[nNurbsIndex_ - 1].vecControlPoint.size() - 1, _preNode);
- }
-
- // 检查下一个节点
- nce::CCamPath::NODE _nextNode;
- if (nPointIndex_ < static_cast<int>(_vecSplines[nNurbsIndex_].vecControlPoint.size()) - 1)
- {
- GenerateNode(_vecSplines, nNurbsIndex_, nPointIndex_ + 1, _nextNode);
- }
- else
- {
- ASSERT(nNurbsIndex_ < static_cast<int>(_vecSplines.size()) - 1);
- if (!_vecSplines[nNurbsIndex_ + 1].vecKnot.empty())
- return;
-
- GenerateNode(_vecSplines, nNurbsIndex_ + 1, 1, _nextNode);
- }
-
- GetScanCutInfo(_preNode, curNode_, _nextNode, ScanCutInfo_);
- }
-
- void CNceParser::GetScanCutInfo(const nce::CCamPath::NODE& preNode_,
- const nce::CCamPath::NODE& curNode_,
- const nce::CCamPath::NODE& nextNode_,
- ScanCutInfo& ScanCutInfo_)
- {
- // 计算前后三段节点的向心向量:如果是直线,则为零向量;如果是圆弧,则为从连接点指向圆心的向量
- INTERPDOUBLE _nxPreEntad = GetArcEntadVector(preNode_, preNode_.ptEnd);
- INTERPDOUBLE _nxCurEntad = GetArcEntadVector(curNode_, curNode_.ptStart);
- INTERPDOUBLE _nxNextEntad = GetArcEntadVector(nextNode_, nextNode_.ptStart);
-
- // 满足以下条件才会对圆扫描中的空程进行单轴联动:
- // 1.当前段为直线,并且其前一段和后一段都为圆弧
- // 2.前一段和后一段的圆弧半径相同,并且在直线的同一侧
- // 3.前一段和后一段的圆弧与直线相切
- if (DOUBLE_NOT_ZERO(_nxCurEntad.GetLength()))
- return;
-
- if (DOUBLE_EQU_ZERO(_nxPreEntad.GetLength()) || DOUBLE_NOT_ZERO((_nxPreEntad - _nxNextEntad).GetLength()))
- return;
-
- // 判断圆弧与直线相切
- INTERPDOUBLE _nxLineVector = INTERPDOUBLE(
- curNode_.ptEnd.x - curNode_.ptStart.x,
- curNode_.ptEnd.y - curNode_.ptStart.y,
- curNode_.ptEnd.z - curNode_.ptStart.z);
- double _nDotProduct = _nxLineVector[axis::x] * _nxNextEntad[axis::x]
- + _nxLineVector[axis::y] * _nxNextEntad[axis::y]
- + _nxLineVector[axis::z] * _nxNextEntad[axis::z];
- if (DOUBLE_NOT_ZERO(_nDotProduct))
- return;
-
- // 圆扫描中的直线空程
- ScanCutInfo_.bIsArcScanCutG0 = true;
- ScanCutInfo_.nRadialRadius = _nxPreEntad.GetLength();
-
- // 获取圆弧所在平面
- ASSERT(preNode_.nType == nextNode_.nType);
- switch (preNode_.nType)
- {
- case nce::CCamPath::nt_arc_xy:
- case nce::CCamPath::nt_circle_xy_ccw:
- case nce::CCamPath::nt_circle_xy_cw:
- ScanCutInfo_.nPlane.SetAxis(axis::x, axis::y);
- break;
- case nce::CCamPath::nt_arc_yz:
- case nce::CCamPath::nt_circle_yz_ccw:
- case nce::CCamPath::nt_circle_yz_cw:
- ScanCutInfo_.nPlane.SetAxis(axis::y, axis::z);
- break;
- case nce::CCamPath::nt_arc_zx:
- case nce::CCamPath::nt_circle_zx_ccw:
- case nce::CCamPath::nt_circle_zx_cw:
- ScanCutInfo_.nPlane.SetAxis(axis::z, axis::x);
- break;
- default:
- ASSERT(false);
- break;
- }
- }
-
- //////////////////////////////////////////////////////////////////////////
- // private function
- void CNceParser::AnalyseHole(const nce::CCamHole* pHole_)
- {
- if (NULL == pHole_)
- {
- ASSERT(false);
- return;
- }
-
- ASSERT(m_pParserModule->m_CodePosition.nAnchorType == ANCH_IDOFFSET);
- if (!CheckStartField(pHole_->GetID()))
- return;
-
- camwrapper::CCamHoleWrapper _CamHoleWrapper(pHole_, m_pParserModule->m_pWCSAdjust, m_pParserModule->m_pAngleToArc);
-
- // 插入安全跳转指令
- INTERPDOUBLE _nxCurPos;
- RetrieveRespPos(_CamHoleWrapper.GetStart(), &_nxCurPos);
- GotoHeadPos(_nxCurPos);
-
- double _nEndZ = _CamHoleWrapper.GetEndZ();
- double _nDepth = _CamHoleWrapper.GetDepth();
- double _nInc = pHole_->GetIncreaseDist();
- double _nBack = pHole_->GetBackDist();
- double _nPauseTime = pHole_->GetPauseTime(); // ms
- // 根据以上参数确定打孔方式
-
- const nce::CParam* _pParam = GetAt_ParamVector(m_pCamParams, pHole_->GetParamIndex());
- ParseParam_Hole(m_pInterpEngine, pHole_, _pParam, &m_ParamHole);
- // 1.解析PrePostCode
- GetPrePostActionCode(m_ParamHole.m_PreActionCode, m_ParamHole.m_PostActionCode);
- UpdateCurrentPos(pHole_->GetID(), 0);
-
- // 将Cam信息发出去,
- SendCamObjInfo(pHole_);
-
- // 1.1 试图插入preCode
- InsertPreActionCode(false);
-
- m_nSystemMaxSpeed = GetMaxSpeedFromPathParam();
-
- // MakeFake for InsertSafeJumpInstruction ---- 杨开锦 2013-02-25
- CNcLine _NcLine_MF(NCFGLINEARINTERP, m_nSystemMaxSpeed, m_pParserModule->m_CodePosition);
- CheckWCSLimit(_nxCurPos, _nxCurPos);
- _NcLine_MF.OrigSetStartPos(_nxCurPos);
- _NcLine_MF.OrigSetEndPos(_nxCurPos);
- AddTailCode(_NcLine_MF);
-
- // 激光打孔,可能只有XY位置信息,直接在上面打一个孔就可以了,用长度为0的NcLine表示
- if (IsInvalidDouble(_nEndZ))
- {
- // 更新孔的文件位置。激光打孔的长度为0,携带的文件位置会被删除
- CNcFilePosition _NcFilePos(NCFCFILEPOSITION, m_pParserModule->m_CodePosition);
- AddTailCode(_NcFilePos);
- // 更新起始比率(正向为0,反向为1)
- SendCamObjStartRateCode();
- CNcLine _NcLine(NCFGLINEARINTERP, m_nSystemMaxSpeed, m_pParserModule->m_CodePosition);
- CheckWCSLimit(_nxCurPos, _nxCurPos);
- _NcLine.OrigSetStartPos(_nxCurPos);
- _NcLine.OrigSetEndPos(_nxCurPos);
- AddTailCode(_NcLine);
- // 更新起始比率(正向为1,反向为0)
- SendCamObjEndRateCode();
- }
- else
- {
- // 更新孔的文件位置。激光打孔的长度为0,携带的文件位置会被删除
- CNcFilePosition _NcFilePos(NCFCFILEPOSITION, m_pParserModule->m_CodePosition);
- AddTailCode(_NcFilePos);
- // 更新起始比率(正向为0,反向为1)
- SendCamObjStartRateCode();
- {
- INTERPDOUBLE _nxTemp = _nxCurPos;
- _nxTemp[NcInterpAxes3::axis::z] -= _nEndZ;
- CheckWCSLimit(_nxCurPos, _nxTemp);
- CheckWCSLimit(_nxTemp, _nxCurPos);
- }
- // XY位置,和孔深,是必然存在的有用信息,当缺少其他尺寸信息的时候不进行回退再进给,一刀打到底
- if (IsInvalidDouble(_nInc) || IsInvalidDouble(_nBack))
- {
- CNcLine _NcLine(NCFGLINEARINTERP, m_nSystemMaxSpeed, m_pParserModule->m_CodePosition);
- _NcLine.OrigSetStartPos(_nxCurPos);
- INTERPDOUBLE _nxTemp = _nxCurPos;
- _nxTemp[NcInterpAxes3::axis::z] -= _nEndZ;
- _NcLine.OrigSetEndPos(_nxTemp);
- AddTailCode(_NcLine);
-
- CNcLine _NcLine2(NCFGRAPIDTRAVERSE, m_pParserModule->m_nSpeedG00, m_pParserModule->m_CodePosition);
- _NcLine2.OrigSetStartPos(_nxTemp);
- _NcLine2.OrigSetEndPos(_nxCurPos);
- AddTailCode(_NcLine2);
- }
- // 将孔加工参数记为:R = 加工起点, Q = 每次进给的深度, D = 每次进给后回
- // 退的距离,Z = 孔底的目标Z坐标, P = 在孔底的暂停时间。 则孔加工方式大都
- // 为:
- // (1)移动到孔上方Z轴安全高度
- // (2)快速移动定位到R点
- // (3)向下加工进给Q切削量深度
- // (4)快速上升D高度
- // (5)向下加工进给D+Q切削深度
- // (6)重复(4)、(5)至到达洞底Z坐标处
- // (7)暂停P毫秒的时间
- // (8)快速上升至Z轴安全高度
- // 在第6步中所说的“至到达洞底Z坐标处”是指,如果向下加工进给时,还没有进给到Q
- // (或D+Q)的深度就已经到达洞底,或者进给了Q(或D+Q)的深度后达到了洞底,都将
- // 结束加工进给,进入7步骤。
- else
- {
- // 目前当前点位置已经是R点
- double _nCurDepth = 0;
- double _nCurZ = _nxCurPos[NcInterpAxes3::axis::z];
- // 步骤3
- {
- CNcLine _NcLineDown(NCFGLINEARINTERP, m_nSystemMaxSpeed, m_pParserModule->m_CodePosition);
- _NcLineDown.OrigSetStartPos(_nxCurPos);
- _NcLineDown.OrigSetStartPos(_nCurZ, NcInterpAxes3::axis::z);
- _nCurDepth = DOUBLE_GE(_nCurDepth + _nInc, _nDepth) ? _nDepth : _nCurDepth + _nInc;
- _nCurZ = _nxCurPos[NcInterpAxes3::axis::z] - _nCurDepth;
- _NcLineDown.OrigSetEndPos(_nxCurPos);
- _NcLineDown.OrigSetEndPos(_nCurZ, NcInterpAxes3::axis::z);
- AddTailCode(_NcLineDown);
- }
- while (DOUBLE_LESS(_nCurDepth, _nDepth))
- {
- // 步骤4
- CNcLine _NcLineUp(NCFGRAPIDTRAVERSE, m_pParserModule->m_nSpeedG00, m_pParserModule->m_CodePosition);
- _NcLineUp.OrigSetStartPos(_nxCurPos);
- _NcLineUp.OrigSetStartPos(_nCurZ, NcInterpAxes3::axis::z);
- _nCurDepth -= _nBack;
- _nCurZ = _nxCurPos[NcInterpAxes3::axis::z] - _nCurDepth;
- _NcLineUp.OrigSetEndPos(_nxCurPos);
- _NcLineUp.OrigSetEndPos(_nCurZ, NcInterpAxes3::axis::z);
- AddTailCode(_NcLineUp);
-
- // 步骤5
- CNcLine _NcLineDown(NCFGLINEARINTERP, m_nSystemMaxSpeed, m_pParserModule->m_CodePosition);
- _NcLineDown.OrigSetStartPos(_nxCurPos);
- _NcLineDown.OrigSetStartPos(_nCurZ, NcInterpAxes3::axis::z);
- _nCurDepth = DOUBLE_GE(_nCurDepth + _nInc + _nBack, _nDepth) ? _nDepth : _nCurDepth + _nInc + _nBack;
- _nCurZ = _nxCurPos[NcInterpAxes3::axis::z] - _nCurDepth;
- _NcLineDown.OrigSetEndPos(_nxCurPos);
- _NcLineDown.OrigSetEndPos(_nCurZ, NcInterpAxes3::axis::z);
- AddTailCode(_NcLineDown);
- }
-
- // 步骤7,缺少孔底暂停时间的时候可以不影响打孔
- if (IsValidDouble(_nPauseTime))
- {
- CNcPause _NcPause(m_pParserModule->m_CodePosition);
- _NcPause.m_nTime = (int)(_nPauseTime);
- AddTailCode(_NcPause);
- }
-
- // 步骤8
- {
- CNcLine _NcLineUp(NCFGRAPIDTRAVERSE, m_pParserModule->m_nSpeedG00, m_pParserModule->m_CodePosition);
- _NcLineUp.OrigSetStartPos(_nxCurPos);
- _NcLineUp.OrigSetStartPos(_nCurZ, NcInterpAxes3::axis::z);
- _NcLineUp.OrigSetEndPos(_nxCurPos);
- ASSERT(DOUBLE_EQU(_NcLineUp.MachGetLength(), _nDepth));
- AddTailCode(_NcLineUp);
- }
- }
- // 更新起始比率(正向为1,反向为0)
- SendCamObjEndRateCode();
- }
-
- // 插入postcode
- InsertPostActionCode();
- CheckEndField(pHole_->GetID());
- }
-
- void CNceParser::AnalyseNormalPath(const nce::CCamPath* pPath_,
- const camwrapper::CCamPathWrapper* pCamPathWrapper_,
- const VECINT& vecScanGXXIndex_,
- StopCornerInfo& StopCornerInfo_)
- {
- const int _nNodeCount = pCamPathWrapper_->GetNodeCount();
- for (int i = 0; i < _nNodeCount; ++i)
- {
- UpdateCurrentPos(pPath_->GetID(), i);
- GenerateStopCornerCode(StopCornerInfo_, _nNodeCount, i);
-
- // 获取扫描切割信息
- ScanCutInfo _ScanCutInfo;
- GetScanCutInfo(pCamPathWrapper_, vecScanGXXIndex_, i, _ScanCutInfo);
- MotionCodeByNodeType(pCamPathWrapper_->GetNode(i), _ScanCutInfo);
- }
- }
-
- void CNceParser::AnalyseNurbsPath(const nce::CCamPath* pPath_,
- const camwrapper::CCamSplineWrapper* pCamSplineWrapper_,
- const VECINT& vecScanGXXIndex_,
- StopCornerInfo& StopCornerInfo_)
- {
- const spline::SplineVector& _vecSplines = pCamSplineWrapper_->GetSplines();
- const int _nNodeCount = pCamSplineWrapper_->GetSegmentCount();
-
- int _nOffset = 0;
- for (int i = 0, _nSize = _vecSplines.size(); i < _nSize; ++i)
- {
- if (!_vecSplines[i].vecKnot.empty())
- {
- // NURBS曲线
- ASSERT(_nOffset < _nNodeCount);
- UpdateCurrentPos(pPath_->GetID(), _nOffset++);
- GenerateStopCornerCode(StopCornerInfo_, _nNodeCount, _nOffset - 1);
-
- NurbsInfo _NurbsInfo;
- GenerateNurbsNode(_vecSplines, i, _NurbsInfo);
-
- // 获取扫描切割信息
- ScanCutInfo _ScanCutInfo;
- GetNurbsScanCutInfo(vecScanGXXIndex_, _ScanCutInfo);
- NurbsCode(_NurbsInfo, _ScanCutInfo);
- continue;
- }
-
- // 直线/圆弧
- int _nNodeNum = _vecSplines[i].vecControlPoint.size();
- for (int j = 1; j < _nNodeNum; ++j)
- {
- ASSERT(_nOffset < _nNodeCount);
- UpdateCurrentPos(pPath_->GetID(), _nOffset++);
- GenerateStopCornerCode(StopCornerInfo_, _nNodeCount, _nOffset - 1);
-
- nce::CCamPath::NODE _node;
- GenerateNode(_vecSplines, i, j, _node);
-
- // 获取扫描切割信息
- ScanCutInfo _ScanCutInfo;
- GetScanCutInfo(pCamSplineWrapper_, vecScanGXXIndex_, _node, i, j, _nOffset - 1, _ScanCutInfo);
- MotionCodeByNodeType(_node, _ScanCutInfo);
- }
- }
-
- ASSERT(_nOffset == _nNodeCount);
- }
-
- nce::CParam* CNceParser::BeforeAnalysePath(const nce::CCamPath* pPath_,
- const camwrapper::CCamSplineWrapper* pCamSplineWrapper_,
- const DPOINT3& ptStartPoint_)
- {
- ASSERT(Forward_Parse == GetParserDir());
-
- // 插入安全跳转指令
- INTERPDOUBLE _nxCurPos;
- RetrieveRespPos(ptStartPoint_, &_nxCurPos);
- GotoHeadPos(_nxCurPos);
-
- // 外部定义的工艺参数
- nce::CParam* _pParam = GetAt_ParamVector(m_pCamParams, pPath_->GetParamIndex());
- ParseParam_Path(m_pInterpEngine, pPath_, _pParam, &m_ParamPath);
-
- GetPrePostActionCode(m_ParamPath.m_PreActionCode, m_ParamPath.m_PostActionCode);
- UpdateCurrentPos(pPath_->GetID(), 0);
-
- GenerateSpindleRevCode();
-
- // 将Cam信息发出去
- SendCamObjInfo(pPath_, pCamSplineWrapper_);
-
- // 试图插入preCode
- InsertPreActionCode(false);
-
- // 获取系统最大加工速度
- m_nSystemMaxSpeed = GetMaxSpeedFromPathParam();
-
- GetSlowlyStartParam(_pParam);
- GetPathMergeableParam(pPath_);
- GetOverArrisSpeedParam(_pParam);
-
- return _pParam;
- }
-
- void CNceParser::AfterAnalysePath(const nce::CCamPath* pPath_, StopCornerInfo& StopCornerInfo_)
- {
- // 插入postcode
- InsertPostActionCode();
- CheckEndField(pPath_->GetID());
-
- while (StopCornerInfo_.listStopCornerCode.GetCount())
- {
- delete StopCornerInfo_.listStopCornerCode.RemoveHead();
- }
- }
-
- void CNceParser::GetNceFilePos(int nID_, int nOffset_, double nRate_, NceFilePos& NceFilePos_) const
- {
- NceFilePos_.SetID(nID_);
- NceFilePos_.SetOffset(nOffset_);
- NceFilePos_.SetRate(nRate_);
- }
-
- void CNceParser::GetPrePostActionCode(PARAM_CSTRING& PreCode, PARAM_CSTRING& PostCode)
- {
- while (m_listPreAction.GetCount())
- delete m_listPreAction.RemoveHead();
-
- while (m_listPostAction.GetCount())
- delete m_listPostAction.RemoveHead();
-
- if (m_pInterpEngine->IsTracking())
- return;
-
- if (PreCode.IsValid())
- ParsePrePostAction(PreCode.m_nValue, m_listPreAction);
-
- if (PostCode.IsValid())
- ParsePrePostAction(PostCode.m_nValue, m_listPostAction);
- }
-
- void CNceParser::ParsePrePostAction(LPCTSTR szParseCode_, NCCODE_LIST& listPrePostCode_)
- {
- CStringA _strSource = (CStringA)szParseCode_;
- // 不发送有效文件标志位,原因同G00EnterLeave
- CFilePosition _CurFP = m_pParserModule->m_CodePosition;
- _CurFP.bIsMainParser = false;
- if (_strSource.IsEmpty())
- return;
-
- int _nStart = 0;
- int _nEnd = 0;
- CStringA _strTemp;
- bool _bBreak = false;
- int _nIntValue = 0;
- float _nDoubleValue = 0.;
- char _nCharValue = 0;
- CStringA _strOut;
-
- while (true)
- {
- if (_bBreak)
- break;
-
- _nEnd = _strSource.Find('\n', _nStart);
- if (_nEnd != -1)
- {
- _strTemp = _strSource.Mid(_nStart, _nEnd - _nStart);
- }
- else
- {
- _strTemp = _strSource.Right(_strSource.GetLength() - _nStart);
- _strTemp.TrimRight();
- _bBreak = true;
- }
-
- _nStart = _nEnd + 1;
- if (_strTemp.IsEmpty())
- continue;
-
- _strOut.Empty();
- _nIntValue = 0;
- int _nAddress = 0;
- int _nLevel = 0;
- int _nTime = 0;
- if (1 == sscanf_s(_strTemp, "OpenPort(%d)", &_nIntValue))
- {
- CNcDirectPort _NcDirectPort(_CurFP);
- _NcDirectPort.m_nPlcAddress = _nIntValue;
- _NcDirectPort.m_bPortValue = 1;
- listPrePostCode_.AddTail(_NcDirectPort.Clone());
- }
- else if (1 == sscanf_s(_strTemp, "ClosePort(%d)", &_nIntValue))
- {
- CNcDirectPort _NcDirectPort(_CurFP);
- _NcDirectPort.m_nPlcAddress = _nIntValue;
- _NcDirectPort.m_bPortValue = 0;
- listPrePostCode_.AddTail(_NcDirectPort.Clone());
- }
- else if (1 == sscanf_s(_strTemp, "Delay(%d)", &_nIntValue))
- {
- CNcPause _NcPause(_CurFP);
- _NcPause.m_nTime = (int)(_nIntValue);
- listPrePostCode_.AddTail(_NcPause.Clone());
- }
- else if (1 == sscanf_s(_strTemp, "Power(%d)", &_nIntValue))
- {
- if (!m_pParserModule->m_bIgnoreProgSpindleRev)
- {
- if (_strTemp.Right(2) == _T("%)"))
- {
- _nIntValue = static_cast<int>(m_pParserModule->GetNamedVariable("#SpindlePort_ProgramRpm") * _nIntValue / 100);
- CNcChangSpindleRev _NcChangSpindleRev(m_pParserModule->m_CodePosition);
- _NcChangSpindleRev.m_nSpindleRev = _nIntValue;
- _NcChangSpindleRev.m_nType = 0;
- listPrePostCode_.AddTail(_NcChangSpindleRev.Clone());
- }
- else
- {
- CNcChangSpindleRev _NcChangSpindleRev(m_pParserModule->m_CodePosition);
- _NcChangSpindleRev.m_nSpindleRev = _nIntValue;
- _NcChangSpindleRev.m_nType = 0;
- listPrePostCode_.AddTail(_NcChangSpindleRev.Clone());
- }
- }
- }
- else if (1 == sscanf_s(_strTemp, "Pressure(%d)", &_nIntValue))
- {
- CNcChangSpindleRev _NcChangSpindleRev(m_pParserModule->m_CodePosition);
- _NcChangSpindleRev.m_nSpindleRev = _nIntValue;
- _NcChangSpindleRev.m_nType = 1;
- listPrePostCode_.AddTail(_NcChangSpindleRev.Clone());
- }
- else if (2 == sscanf_s(_strTemp, "PWM(%d,%d)", &_nIntValue, &_nLevel))
- {
- ASSERT(_strTemp.Right(2) == _T("%)"));
- CNcChangSpindleRev _NcChangSpindleRev(m_pParserModule->m_CodePosition);
- _NcChangSpindleRev.m_nSpindleRev = _nIntValue;
- _NcChangSpindleRev.m_nType = 2;
- listPrePostCode_.AddTail(_NcChangSpindleRev.Clone());
-
- _NcChangSpindleRev.m_nSpindleRev = _nLevel;
- _NcChangSpindleRev.m_nType = 3;
- listPrePostCode_.AddTail(_NcChangSpindleRev.Clone());
- }
- else if (1 == sscanf_s(_strTemp, "MaxPower(%d)", &_nIntValue))
- {
- CNcChangSpindleRev _NcChangSpindleRev(m_pParserModule->m_CodePosition);
- _NcChangSpindleRev.m_nSpindleRev = _nIntValue;
- _NcChangSpindleRev.m_nType = 4;
- listPrePostCode_.AddTail(_NcChangSpindleRev.Clone());
- }
- else if (3 == sscanf_s(_strTemp, "ReservedSVC%d(%d%c", &_nLevel, &_nIntValue, &_nCharValue) && _nCharValue == ')')
- {
- // 增加备用模拟量指令,Pressure在图层动作中已经被叫做备用模拟量
- // 这里增的备用模拟量都从1开始:备用模拟量1、备用模拟量2.......
- // m_nType从11开始,预留10组模拟量。指定ReservedSVC1的m_nType应
- // 为11,ReservedSVC10的m_nType应为20 ---- DingQiang 2015-01-04
- ASSERT(_nLevel >=1 && _nLevel <= 10);
- CNcChangSpindleRev _NcChangSpindleRev(m_pParserModule->m_CodePosition);
- _NcChangSpindleRev.m_nSpindleRev = _nIntValue;
- _NcChangSpindleRev.m_nType = (_nLevel + 10);
- listPrePostCode_.AddTail(_NcChangSpindleRev.Clone());
- }
- else if (2 == sscanf_s(_strTemp, "ReservedSVC%d(%f)", &_nLevel, &_nDoubleValue))
- {
- // 小数扩大10倍再发下去,并且type从20开始计 ---- DingQiang 2016-04-12
- ASSERT(_nLevel >=1 && _nLevel <= 10);
- CNcChangSpindleRev _NcChangSpindleRev(m_pParserModule->m_CodePosition);
- _NcChangSpindleRev.m_nSpindleRev = static_cast<int>(_nDoubleValue * 10 + 0.5);
- _NcChangSpindleRev.m_nType = (_nLevel + 20);
- listPrePostCode_.AddTail(_NcChangSpindleRev.Clone());
- }
- else if (3 == sscanf_s(_strTemp, "WaitPort(%d,%d,%d)", &_nAddress, &_nLevel, &_nTime))
- {
- // 增加等待端口 ---- DingQiang 2012-09-22
- CNcWaitPort _NcWaitPort(_CurFP);
- _NcWaitPort.m_nPlcAddress = _nAddress;
- _NcWaitPort.m_bPortValue = (_nLevel != 0);
- _NcWaitPort.m_nTimeOut = _nTime;
- listPrePostCode_.AddTail(_NcWaitPort.Clone());
- }
- else if (2 == sscanf_s(_strTemp, "WaitPort(%d,%d)", &_nAddress, &_nLevel))
- {
- // 增加等待端口 ---- DingQiang 2012-09-22
- CNcWaitPort _NcWaitPort(_CurFP);
- _NcWaitPort.m_nPlcAddress = _nAddress;
- _NcWaitPort.m_bPortValue = (_nLevel != 0);
- _NcWaitPort.m_nTimeOut = INT_MAX;
- listPrePostCode_.AddTail(_NcWaitPort.Clone());
- }
- else if (-1 != _strTemp.Find("OpenPort"))
- {
- int _nS = _strTemp.Find('(') + 1;
- int _nE = _strTemp.Find(')');
- _strOut = _strTemp.Mid(_nS, _nE - _nS);
- _strOut.TrimLeft();
- _strOut.TrimRight();
- int _nPortAdd = static_cast<int>(m_pParserModule->GetNamedVariable(_strOut));
- CNcDirectPort _NcDirectPort(_CurFP);
- _NcDirectPort.m_nPlcAddress = _nPortAdd;
- _NcDirectPort.m_bPortValue = 1;
- listPrePostCode_.AddTail(_NcDirectPort.Clone());
- }
- else if (-1 != _strTemp.Find("ClosePort"))
- {
- int _nS = _strTemp.Find('(') + 1;
- int _nE = _strTemp.Find(')');
- _strOut = _strTemp.Mid(_nS, _nE - _nS);
- _strOut.TrimLeft();
- _strOut.TrimRight();
- int _nPortAdd = static_cast<int>(m_pParserModule->GetNamedVariable(_strOut));
- CNcDirectPort _NcDirectPort(_CurFP);
- _NcDirectPort.m_nPlcAddress = _nPortAdd;
- _NcDirectPort.m_bPortValue = 0;
- listPrePostCode_.AddTail(_NcDirectPort.Clone());
- }
- else if (-1 != _strTemp.Find("WaitPort"))
- {
- int _nS = _strTemp.Find('(') + 1;
- int _nE = _strTemp.Find(')');
- _strOut = _strTemp.Mid(_nS, _nE - _nS);
- _strOut.TrimLeft();
- _strOut.TrimRight();
-
- // 端口地址
- _nS = _strOut.Find(',');
- CStringA _strPortAdd = _strOut.Left(_nS);
- int _nPortAdd = static_cast<int>(m_pParserModule->GetNamedVariable(_strPortAdd));
- _nS += 1;
-
- // 端口值
- CString _strLevel;
- _nE = _strOut.Find(',', _nS);
- if (_nE == -1)
- {
- _strLevel = _strOut.Mid(_nS, _strOut.GetLength() - _nS);
- _nLevel = atoi(_strLevel);
- _nTime = INT_MAX;
- }
- else
- {
- _strLevel = _strOut.Mid(_nS, _nE - _nS);
- _nLevel = atoi(_strLevel);
- _nE += 1;
-
- // 等待时间
- CString _strTime = _strOut.Mid(_nE, _strOut.GetLength() - _nE);
- _nTime = atoi(_strTime);
- }
-
- CNcWaitPort _NcWaitPort(_CurFP);
- _NcWaitPort.m_nPlcAddress = _nPortAdd;
- _NcWaitPort.m_bPortValue = (_nLevel != 0);
- _NcWaitPort.m_nTimeOut = _nTime;
- listPrePostCode_.AddTail(_NcWaitPort.Clone());
- }
- else if (-1 != _strTemp.Find("MSG"))
- {
- CNcSendRawString _NcSendRawString(_CurFP);
-
- int _nS = _strTemp.Find('(') + 1;
- int _nE = _strTemp.Find(')');
- _strOut = _strTemp.Mid(_nS, _nE - _nS);
- _NcSendRawString.m_strString = _strOut;
- listPrePostCode_.AddTail(_NcSendRawString.Clone());
- }
- else if (-1 != _strTemp.Find("Delay"))
- {
- int _nS = _strTemp.Find('(') + 1;
- int _nE = _strTemp.Find(')');
- _strOut = _strTemp.Mid(_nS, _nE - _nS);
- _strOut.TrimLeft();
- _strOut.TrimRight();
- int _nTime = static_cast<int>(m_pParserModule->GetNamedVariable(_strOut));
- CNcPause _NcPause(_CurFP);
- _NcPause.m_nTime = (int)_nTime;
- listPrePostCode_.AddTail(_NcPause.Clone());
- }
- }
- }
-
- void CNceParser::InsertPreActionCode(bool bForce_/* = false*/)
- {
- if (m_listPreAction.IsEmpty())
- return;
-
- POSITION _pos = m_listPreAction.GetHeadPosition();
- bool _bNeedClear = false;
-
- if (!bForce_ && m_bPrePostActionValid)
- {
- // 非断点继续时判断写入队列
- while (_pos != NULL)
- AddTailCode(*m_listPreAction.GetNext(_pos));
-
- _bNeedClear = true;
- }
- else if (bForce_)
- {
- // 断点继续时当前断点继续所在图形的precode需要强行写入队列
- while (_pos != NULL)
- m_pParserModule->AddTailCode(*m_listPreAction.GetNext(_pos));
-
- _bNeedClear = true;
- // 第一次强行插入PreAction后,意味着以后的Pre_PostAction可以正常插入了 lingshu 20120328
- m_bPrePostActionValid = true;
- }
-
- if (_bNeedClear)
- {
- while (m_listPreAction.GetCount())
- delete m_listPreAction.RemoveHead();
- }
- }
-
- void CNceParser::InsertPostActionCode()
- {
- if (m_listPostAction.IsEmpty())
- return;
-
- if (m_bPrePostActionValid)
- {
- POSITION _pos = m_listPostAction.GetHeadPosition();
- while (_pos != NULL)
- m_pParserModule->AddTailCode(*m_listPostAction.GetNext(_pos));
-
- while (m_listPostAction.GetCount())
- delete m_listPostAction.RemoveHead();
- }
- }
-
- void CNceParser::GetArcPlane(const nce::CCamPath::NODE& node_, CNcArc* pArcCode_)
- {
- switch (node_.nType)
- {
- case nce::CCamPath::nt_arc_xy:
- pArcCode_->m_nPlane.SetAxis(axis::x, axis::y);
- break;
-
- case nce::CCamPath::nt_arc_yz:
- pArcCode_->m_nPlane.SetAxis(axis::y, axis::z);
- break;
-
- case nce::CCamPath::nt_arc_zx:
- pArcCode_->m_nPlane.SetAxis(axis::z, axis::x);
- break;
-
- default:
- ASSERT(false);
- break;
- }
- }
-
- void CNceParser::GetCirclePlaneAndDirectory(const nce::CCamPath::NODE& node_, CNcArc* pArcCode_)
- {
- switch (node_.nType)
- {
- case nce::CCamPath::nt_circle_xy_cw:
- pArcCode_->m_nPlane.SetAxis(axis::x, axis::y);
- pArcCode_->m_nFunTag = NCFGARCINTERPCW;
- break;
-
- case nce::CCamPath::nt_circle_xy_ccw:
- pArcCode_->m_nPlane.SetAxis(axis::x, axis::y);
- pArcCode_->m_nFunTag = NCFGARCINTERPCCW;
- break;
-
- case nce::CCamPath::nt_circle_yz_cw:
- pArcCode_->m_nPlane.SetAxis(axis::y, axis::z);
- pArcCode_->m_nFunTag = NCFGARCINTERPCW;
- break;
-
- case nce::CCamPath::nt_circle_yz_ccw:
- pArcCode_->m_nPlane.SetAxis(axis::y, axis::z);
- pArcCode_->m_nFunTag = NCFGARCINTERPCCW;
- break;
-
- case nce::CCamPath::nt_circle_zx_cw:
- pArcCode_->m_nPlane.SetAxis(axis::z, axis::x);
- pArcCode_->m_nFunTag = NCFGARCINTERPCW;
- break;
-
- case nce::CCamPath::nt_circle_zx_ccw:
- pArcCode_->m_nPlane.SetAxis(axis::z, axis::x);
- pArcCode_->m_nFunTag = NCFGARCINTERPCCW;
- break;
-
- default:
- ASSERT(false);
- break;
- }
- }
-
- bool CNceParser::RetrieveSpindleRevFromPathParam(OUT int* pnSpindleRev_)
- {
- int _nSpindleRev = 0;
- if (m_ParamPath.m_Power.IsValid() && DOUBLE_NOT_ZERO(m_ParamPath.m_Power.m_nValue))
- {
- _nSpindleRev = int(m_ParamPath.m_Power.m_nValue);
- _nSpindleRev = static_cast<int>(m_pParserModule->GetNamedVariable("#SpindlePort_ProgramRpm") * _nSpindleRev / 100);
- }
- else
- return false;
-
- *pnSpindleRev_ = _nSpindleRev;
- return true;
- }
-
- bool CNceParser::CheckTinyArc(double nCentralAngle_, double nRadius_)
- {
- ASSERT((nCentralAngle_ > 0.) && (nRadius_ > 0.));
-
- // 超过1/4圆弧
- if (nCentralAngle_ >= 0.5 * c_nPIE)
- return false;
-
- // 检查弓高误差
- const static double _s_nMaxChordError = 1.e-6;
- double _nChordError = nRadius_ - nRadius_ * cos(0.5 * nCentralAngle_);
- ASSERT(_nChordError >= 0.);
- if (_nChordError > _s_nMaxChordError)
- return false;
-
- return true;
- }
-
- void CNceParser::ModifyMotionCodeRate(CNcMotion* pMotionCode_)
- {
- // 根据外部传入的起始和终止比率,修改所在段生成的NcMotion的加工比率
- if ((m_nEntityID == m_CurField.idoff_from.nID) && (m_nIndexOff == m_CurField.idoff_from.nOffset)
- && DOUBLE_NOT_ZERO(m_CurField.idoff_from.nRate))
- pMotionCode_->m_MachineField.nFrom = m_CurField.idoff_from.nRate;
-
- if ((m_nEntityID == m_CurField.idoff_to.nID) && (m_nIndexOff == m_CurField.idoff_to.nOffset)
- && DOUBLE_NOT_ZERO(m_CurField.idoff_to.nRate))
- pMotionCode_->m_MachineField.nTo = m_CurField.idoff_to.nRate;
- }
-
- void CNceParser::CheckWCSLimitForArc(const CNcArc* pArcCode_)
- {
- if (!IsMainParser())
- return;
-
- INTERPDOUBLE _nxMCSMin;
- INTERPDOUBLE _nxMCSMax;
- pArcCode_->GetCoorMinMax(_nxMCSMin, _nxMCSMax);
-
- CheckWCSLimit(_nxMCSMin, _nxMCSMax);
- CheckWCSLimit(_nxMCSMax, _nxMCSMin);
- }
-
- void CNceParser::CheckWCSLimitForNurbs(const VECINTERDOUBLE& vecControlPoint_)
- {
- if (!IsMainParser() || vecControlPoint_.empty())
- return;
-
- INTERPDOUBLE _nxMCSMin = vecControlPoint_.front();
- INTERPDOUBLE _nxMCSMax = vecControlPoint_.front();
- for (int i = 1, _nSize = vecControlPoint_.size(); i < _nSize; ++i)
- {
- for (int j = axis::x; j <= axis::z; ++j)
- {
- if (_nxMCSMin[j] > vecControlPoint_[i][j])
- _nxMCSMin[j] = vecControlPoint_[i][j];
- if (_nxMCSMax[j] < vecControlPoint_[i][j])
- _nxMCSMax[j] = vecControlPoint_[i][j];
- }
- }
-
- CheckWCSLimit(_nxMCSMin, _nxMCSMax);
- CheckWCSLimit(_nxMCSMax, _nxMCSMin);
- }
-
- void CNceParser::MoveToDestPos(const INTERPDOUBLE& nxDestPos_)
- {
- INTERPDOUBLE _nxCurPos = m_pParserModule->m_nxJumpPos;
- // 加载轨迹时当前点无效
- if (IsInvalidDouble(_nxCurPos[NcInterpAxes3::axis::x])
- || IsInvalidDouble(_nxCurPos[NcInterpAxes3::axis::y])
- || IsInvalidDouble(_nxCurPos[NcInterpAxes3::axis::z]))
- return;
-
- double _nOffset = (nxDestPos_ - _nxCurPos).GetLength();
- if (DOUBLE_EQU_ZERO(_nOffset))
- return;
-
- CNcLine _NcLine(NCFGRAPIDTRAVERSE, m_pParserModule->m_nSpeedG00, m_pParserModule->m_CodePosition);
- _NcLine.OrigSetStartPos(_nxCurPos);
- _NcLine.OrigSetEndPos(nxDestPos_);
- _NcLine.m_bFromProgram = false;
- AddTailCode(_NcLine);
- }
-
- void CNceParser::SendCamObjInfo(const nce::CCamObject* pCamObject_, const camwrapper::CCamSplineWrapper* pCamSplineWrapper_ /* = NULL */)
- {
- // CamType
- CNcSendRawString _NcSendRawString(m_pParserModule->m_CodePosition);
- static const struct CTItem
- {
- CString strStringName;
- nce::cam_t nEnumName;
- } _s_cCTItem[] =
- {
- {"camobject", nce::camobject},
- {"camhole", nce::camhole},
- {"campath", nce::campath},
- {"camgroup", nce::camgroup},
- {"camscanlines", nce::camscanlines},
- };
-
- for (int _i = 0; _i < _countof(_s_cCTItem); _i++)
- {
- if (pCamObject_->GetType() == _s_cCTItem[_i].nEnumName)
- {
- _NcSendRawString.m_strString.Format("${ext:CamType=%s}", _s_cCTItem[_i].strStringName);
- AddTailCode(_NcSendRawString, true);
- break;
- }
- }
-
- // CamID
- _NcSendRawString.m_strString.Format("${ext:CamID=%d}", pCamObject_->GetID());
- AddTailCode(_NcSendRawString, true);
-
- // CamParamIndex
- _NcSendRawString.m_strString.Format("${ext:CamParamIndex=%d}", pCamObject_->GetParamIndex());
- AddTailCode(_NcSendRawString, true);
-
- // CamParamString
- RecordScanNodePos(pCamObject_, pCamSplineWrapper_);
-
- // 每次发送200,发多了不行,驱动校验不过 ---- DingQiang 2015-03-14
- const int _nEverySendCounts = 200;
- CString _strParamString = pCamObject_->GetParamString();
- int _nSendCounts = 0;
- int _nNeedSendCounts = _strParamString.GetLength();
- int _nPackageIndex = 0;
- while (_nSendCounts <= _nNeedSendCounts)
- {
- if (_nNeedSendCounts - _nSendCounts >= _nEverySendCounts)
- {
- _NcSendRawString.m_strString.Format("${ext:CamParamString%d=%s}",
- _nPackageIndex, _strParamString.Mid(_nSendCounts, _nEverySendCounts));
- }
- else
- {
- _NcSendRawString.m_strString.Format("${ext:CamParamString%d=%s}",
- _nPackageIndex, _strParamString.Mid(_nSendCounts, _nNeedSendCounts - _nSendCounts));
- }
-
- AddTailCode(_NcSendRawString, true);
- _nSendCounts += _nEverySendCounts;
- _nPackageIndex++;
- }
-
- _NcSendRawString.m_strString.Format("${ext:CamParamString%d=%s}", _nPackageIndex,"");
- AddTailCode(_NcSendRawString, true);
- }
-
- void CNceParser::RecordScanNodePos(const nce::CCamObject* pCamObject_, const camwrapper::CCamSplineWrapper* pCamSplineWrapper_)
- {
- ASSERT(pCamObject_);
- if ((pCamObject_->GetType() != nce::campath) || !m_bScanPath)
- return;
-
- nce::CCamPath* _pCamPath = (nce::CCamPath*)pCamObject_;
- if (pCamSplineWrapper_ && pCamSplineWrapper_->IsSpline() && (pCamSplineWrapper_->GetSegmentCount() > 0))
- {
- // 样条拟合路径
- CString _strKey = "NodeCount";
- CString _strValue;
- _strValue.Format("%d", pCamSplineWrapper_->GetSegmentCount());
- _pCamPath->SetKey(_strKey, _strValue);
-
- _strKey = "NodeDeltaPos";
- _strValue.Empty();
- DPOINT3 _ptStart = _pCamPath->GetStartPoint();
- const spline::SplineVector& _vecSplines = pCamSplineWrapper_->GetSplines();
- ASSERT(DOUBLE_EQU(_ptStart.x, _vecSplines.front().vecControlPoint.front().nEndX));
- ASSERT(DOUBLE_EQU(_ptStart.y, _vecSplines.front().vecControlPoint.front().nEndY));
- for (int i = 0, _nSize = _vecSplines.size(); i < _nSize; ++i)
- {
- if (_vecSplines[i].vecKnot.empty())
- {
- // 直线/圆弧
- int _nNodeNum = _vecSplines[i].vecControlPoint.size();
- for (int j = 0; j < _nNodeNum - 1; ++j)
- {
- double _nDeltaX = _vecSplines[i].vecControlPoint[j].nEndX - _ptStart.x;
- double _nDeltaY = _vecSplines[i].vecControlPoint[j].nEndY - _ptStart.y;
- _strValue.AppendFormat("(%.4f,%.4f)", _nDeltaX, _nDeltaY);
- }
- }
- else
- {
- // NURBS曲线
- ASSERT(!_vecSplines[i].vecControlPoint.empty());
- double _nDeltaX = _vecSplines[i].vecControlPoint.front().nEndX - _ptStart.x;
- double _nDeltaY = _vecSplines[i].vecControlPoint.front().nEndY - _ptStart.y;
- _strValue.AppendFormat("(%.4f,%.4f)", _nDeltaX, _nDeltaY);
- }
- }
-
- _pCamPath->SetKey(_strKey, _strValue);
- }
- else
- {
- CString _strKey = "NodeCount";
- CString _strValue;
- _strValue.Format("%d", _pCamPath->GetNodeCount());
- _pCamPath->SetKey(_strKey, _strValue);
-
- _strKey = "NodeDeltaPos";
- _strValue.Empty();
- DPOINT3 _ptStart = _pCamPath->GetStartPoint();
- for (int _i = 0; _i < static_cast<int>(_pCamPath->GetNodeCount()); _i++)
- {
- DPOINT3 _ptDelta = _pCamPath->GetNode(_i).ptStart - _ptStart;
- _strValue.AppendFormat("(%.4f,%.4f)", _ptDelta.x, _ptDelta.y);
- }
-
- _pCamPath->SetKey(_strKey, _strValue);
- }
- }
-
- INTERPDOUBLE CNceParser::GetArcEntadVector(const nce::CCamPath::NODE& node_, const DPOINT3& nxConnectPoint_)
- {
- INTERPDOUBLE _nxArcEntadVector(0., 0., 0.);
- switch (node_.nType)
- {
- case nce::CCamPath::nt_arc_xy:
- case nce::CCamPath::nt_arc_yz:
- case nce::CCamPath::nt_arc_zx:
- {
- int _nFirstIndex = 0;
- int _nSecondIndex = 0;
- if (nce::CCamPath::nt_arc_xy == node_.nType)
- {
- _nFirstIndex = axis::x;
- _nSecondIndex = axis::y;
- }
- else if (nce::CCamPath::nt_arc_yz == node_.nType)
- {
- _nFirstIndex = axis::y;
- _nSecondIndex = axis::z;
- }
- else
- {
- _nFirstIndex = axis::z;
- _nSecondIndex = axis::x;
- }
-
- DPOINT2 _ptStart(node_.ptStart[_nFirstIndex], node_.ptStart[_nSecondIndex]);
- DPOINT2 _ptEnd(node_.ptEnd[_nFirstIndex], node_.ptEnd[_nSecondIndex]);
- DPOINT2 _ptCenter;
- double _nStartAngle = 0.;
- double _nEndAngle = 0.;
- double _nRadius = 0.;
- RetrieveArcInf(_ptStart, _ptEnd, node_.nBulge, _ptCenter, _nStartAngle, _nEndAngle, _nRadius);
-
- INTERPDOUBLE _nxConnectPoint(nxConnectPoint_.x, nxConnectPoint_.y, nxConnectPoint_.z);
- _nxArcEntadVector[_nFirstIndex] = _ptCenter.x - _nxConnectPoint[_nFirstIndex];
- _nxArcEntadVector[_nSecondIndex] = _ptCenter.y - _nxConnectPoint[_nSecondIndex];
- }
- break;
-
- case nce::CCamPath::nt_circle_xy_cw:
- case nce::CCamPath::nt_circle_xy_ccw:
- case nce::CCamPath::nt_circle_yz_cw:
- case nce::CCamPath::nt_circle_yz_ccw:
- case nce::CCamPath::nt_circle_zx_cw:
- case nce::CCamPath::nt_circle_zx_ccw:
- {
- _nxArcEntadVector = INTERPDOUBLE(
- node_.ptCenter.x - node_.ptStart.x,
- node_.ptCenter.y - node_.ptStart.y,
- node_.ptCenter.z - node_.ptStart.z);
- }
- break;
-
- default:
- break;
- }
-
- return _nxArcEntadVector;
- }
-
- void CNceParser::GetStopCornerInfo(const nce::CCamPath* pPath_, const nce::CParam* pParam_, StopCornerInfo& StopCornerInfo_)
- {
- // 角点停顿功能 ---- 杨开锦 2015-11-30
- // 在CAM对象中的信息形如 StopCorner=1,5,256;
- // 在图层中的信息形如 StopCornerDelay=1000;
- StopCornerInfo_.strStopCornerIndex = pPath_->GetKey("StopCorner");
- StopCornerInfo_.nStopCornerIndex = StopCornerInfo_.strStopCornerIndex.IsEmpty() ? -1 : atoi(StopCornerInfo_.strStopCornerIndex);
- ASSERT(StopCornerInfo_.nStopCornerIndex == -1
- || StopCornerInfo_.nStopCornerIndex > 0
- && StopCornerInfo_.nStopCornerIndex <= (int)pPath_->GetNodeCount());
-
- CStringA _strStopCorner; // 角点停顿的动作写到lua中 ---- 杨开锦 2016-03-09
- ParseParam_GetActionString(m_pInterpEngine, pPath_, pParam_, "getStringCoolingAction", &_strStopCorner);
- ParsePrePostAction(_strStopCorner, StopCornerInfo_.listStopCornerCode);
- }
-
- void CNceParser::GenerateStopCornerCode(StopCornerInfo& StopCornerInfo_, int nNodeCount_, int nNodeIndex_)
- {
- if (StopCornerInfo_.nStopCornerIndex != nNodeIndex_)
- return;
-
- // 角点处的停顿算是对下一段的加工预处理,即,理解为先要冷却再开始切下一段 ---- 杨开锦 2015-11-30
- if (m_bPrePostActionValid)
- {
- POSITION _pos = StopCornerInfo_.listStopCornerCode.GetHeadPosition();
- while (_pos)
- {
- AddTailCode(*StopCornerInfo_.listStopCornerCode.GetNext(_pos));
- }
- }
-
- StopCornerInfo_.nStopCornerIndex = StopCornerInfo_.strStopCornerIndex.Find(",");
- if (StopCornerInfo_.nStopCornerIndex >= 0)
- {
- StopCornerInfo_.strStopCornerIndex = StopCornerInfo_.strStopCornerIndex.Mid(StopCornerInfo_.nStopCornerIndex + 1);
- StopCornerInfo_.nStopCornerIndex = StopCornerInfo_.strStopCornerIndex.IsEmpty() ? -1 : atoi(StopCornerInfo_.strStopCornerIndex);
- }
-
- ASSERT(StopCornerInfo_.nStopCornerIndex == -1
- || StopCornerInfo_.nStopCornerIndex > 0
- && StopCornerInfo_.nStopCornerIndex <= nNodeCount_);
- }
-
- void CNceParser::InitSlowStartInfo()
- {
- ASSERT(IsValidDouble(m_nSystemMaxSpeed) && DOUBLE_GREAT_ZERO(m_nSystemMaxSpeed));
-
- // 慢速起步生效条件:
- // 1.正向解析
- // 2.启用慢速起步功能
- // 3.慢速起步距离大于零
- // 4.慢速起步速度大于零
- // 5.慢速起步速度小于系统允许的最大速度
- m_bEnableSlowlyStart = (GetParserDir() == Forward_Parse)
- && m_pInterpEngine->m_pInterpData->m_bSlowlyStart
- && m_SlowlyStartLayerParam.m_bSlowlyStart
- && DOUBLE_GREAT_ZERO(m_SlowlyStartLayerParam.m_nSlowlyStartLen)
- && DOUBLE_GREAT_ZERO(m_SlowlyStartLayerParam.m_nSlowlyStartSpeed)
- && DOUBLE_LESS(m_SlowlyStartLayerParam.m_nSlowlyStartSpeed, m_nSystemMaxSpeed);
- m_nSlowlyStartSumLen = 0.;
- }
-
- void CNceParser::ResetSlowStartInfo()
- {
- m_bEnableSlowlyStart = false;
- m_nSlowlyStartSumLen = 0.;
- }
-
- void CNceParser::SplitMotionBySlowStart(CNcMotion& MotionCode_)
- {
- // 断点继续时跳过已经加工的段
- if (!(GetCurPosField() & CCodeParser::FP_MIDDLE))
- {
- m_pParserModule->m_nxJumpPos = MotionCode_.MachGetEndPos();
- return;
- }
-
- if (!m_bEnableSlowlyStart || DOUBLE_GE(m_nSlowlyStartSumLen, m_SlowlyStartLayerParam.m_nSlowlyStartLen))
- {
- AddTailCode(MotionCode_);
- return;
- }
-
- ASSERT(!MotionCode_.IsConverseMotion());
- if (DOUBLE_LE(m_nSlowlyStartSumLen + MotionCode_.MachGetLength(), m_SlowlyStartLayerParam.m_nSlowlyStartLen))
- {
- // 将运动指令的最大速度调整为慢速起步速度
- ASSERT(DOUBLE_LE(m_SlowlyStartLayerParam.m_nSlowlyStartSpeed, MotionCode_.m_nMaxSpeed));
- MotionCode_.m_nMaxSpeed = m_SlowlyStartLayerParam.m_nSlowlyStartSpeed;
- m_nSlowlyStartSumLen += MotionCode_.MachGetLength();
- AddTailCode(MotionCode_);
- return;
- }
-
- double _nSplitLength = m_SlowlyStartLayerParam.m_nSlowlyStartLen - m_nSlowlyStartSumLen;
- ASSERT(DOUBLE_GREAT_ZERO(_nSplitLength) && DOUBLE_LESS(_nSplitLength, MotionCode_.MachGetLength()));
- m_nSlowlyStartSumLen += _nSplitLength;
- SplitMotionByLength(this, MotionCode_, _nSplitLength);
- }
|