情况是这样的,框架我已经写好了,主要是在点阵上绘制电子器件,并且把器件互相连通,然后还要保存成文件,以后读出来再编辑,我现在状态不佳,脑袋里一团酱糊,希望高人能给点思路,谢谢各位高人!!!

解决方案 »

  1.   

    曾经有过累似想法,但是没有实施。
    当时我想的通过GDI绘图实现,不论是器件也好,连接线也好都是用基本的GDI函数来画的,针对每个器件记录好位置、线宽、颜色及作图步骤,这样可以保存到文件中,也可从文件读取。
    比较重要是如何处理好缩放及拖动,以及各个器件的同步。原则上来说这个方法可行。
      

  2.   

    我现在用的是一套SDI单文档的框架,自己加了一套可自动缩动的窗口,实现为使用者提供器件选择,然View里在OnDraw里面调用自己写的一个绘制点阵的方法,但是点阵坐标暂时还没有存储起来,毕竟写这个我还只花了十五天左右的时间,没时间太完善,项目又催得紧,大虾帮忙啊
      

  3.   

    我也是考虑到缩放的问题才没想到有什么好的方法去解决,我目前是用的是vector,做为器件的容器,然后使用多态的方式来存储器件对象指针,结果用vector也遇到了问题,用push_back方法追回成员的时候,竟然只能加32个,加多了就报错
      

  4.   

    不可能啊,vector怎么会有这种限制?
      

  5.   

    //===父类的声明==============================================================
    class CShape  //器件形状  父类
    {
    public: 
    //virtual int  CheckAfoul();///检测碰撞
    void SetEndPoint(const int x, const int y);
    void SetEndPoint(const CPoint * p);
    CPoint * GetCoord2();
    void SetCoord(const CPoint *p);
    CPoint * GetCoord();
    void SetCoord(const int  m_x, const int m_y);
    int GetType();
    void SetType(int Type);
    BOOL m_DrawOrNot ;//是否绘制
    CShape();
    virtual ~CShape();
    protected:
    CPoint P_Star; // 记忆的点应为器件点表中相对坐标点  起始点
    CPoint P_End;// 记忆的点应为器件点表中相对坐标点  结束点
    int m_Type;
    };
    //====出错的地方============================================================
    vector <CShape *> m_spArr;
    void CUIView::drawToCanvas( CShape *pShape)
    {
    ASSERT(pShape   !=   NULL);   

    m_spArr.push_back(pShape);
    }
      

  6.   

    //===完整的声明代码================================================
    #include <vector>
    using namespace std;
    class CShape  //器件形状  父类
    {
    public: 
    //virtual int  CheckAfoul();///检测碰撞
    void SetEndPoint(const int x, const int y);
    void SetEndPoint(const CPoint * p);
    CPoint * GetCoord2();
    void SetCoord(const CPoint *p);
    CPoint * GetCoord();
    void SetCoord(const int  m_x, const int m_y);
    int GetType();
    void SetType(int Type);
    BOOL m_DrawOrNot ;//是否绘制
    CShape();
    virtual ~CShape();
    protected:
    CPoint P_Star; // 记忆的点应为器件点表中相对坐标点  起始点
    CPoint P_End;// 记忆的点应为器件点表中相对坐标点  结束点
    int m_Type;
    };class CLine :public CShape   //连接线对象
    {
    public:
    int x_Star;
    int y_Star;
    int x_End;
    int y_End;
    int m_x1;
    int m_x2;
    int m_y1;
    int m_y2;
    int x1;
    int y1;
    int x2;
    int y2; void DrawLine(CDC *pDC, int m_Unit , int nChar, int Val);
    CLine();
    virtual ~CLine();
    };class CControl :public CShape  //控制器对象
    {
    public:
    void  GetFrame(CPoint * pStar, CPoint * pEnd);
    int m_x1;
    int m_x2;
    int m_y1;
    int m_y2;
    int x1;
    int y1; void DrawControl(CDC *pDC, int m_Unit, int nChar, int Val);
    CControl();
    virtual ~CControl();
    };
    class CPointRay :public CShape   //灯点对象   //灯点必需有连接线连接控制器端口才可以被点亮
    {
    public:
    typedef struct _conn {
      BOOL b_Conn;
      DWORD m_Number;
      DWORD m_port;
    public:
    void SetUpLine(CLine * pLine);
    } CONN;
    CLine * LineToUp;
    CLine * LineToDown;

    void SetUpLine(CLine * pLine);
    CLine * GetUpLine();
    void SetDownLine(CLine * pLine);
    CLine * GetDownLine(); int m_x1;
    int m_x2;
    int m_y1;
    int m_y2;
    int x1;
    int y1;
    CONN  type_conn;
    void DrawPoint(CDC * pDC, int m_Unit, int nChar, int Val);
    CPointRay();
    virtual ~CPointRay();};//==完整CShape及子类实现代码============================
    CShape::CShape():m_DrawOrNot(true)
    {
    P_Star.x = -1;
    P_Star.y = -1;
    }CShape::~CShape()
    {}void CShape::SetType(int Type)
    {
    m_Type = Type;
    }int CShape::GetType()
    {
    return m_Type;
    }void CShape::SetCoord(const int m_x, const int m_y)
    {
    P_Star.x = m_x;}CPoint * CShape::GetCoord()
    {
    return &P_Star;
    }void CShape::SetCoord(const  CPoint * p)
    {
    P_Star = *p;
    }CPoint * CShape::GetCoord2()
    {
    return &P_End;
    }
    //==============================================================================================================CPointRay::CPointRay()
    {
    m_x1 = 0;
    m_x2 = 0;
    m_y1 = 0;
    m_y2 = 0;
    x1 = 0;
    y1 = 0;
    type_conn.b_Conn = FALSE;
    type_conn.m_Number = -1;
    type_conn.m_port = -1;
    LineToUp = NULL;
    LineToDown = NULL;
    }CPointRay::~CPointRay()
    {}void CPointRay::DrawPoint(CDC *pDC, int m_Unit, int nChar, int Val)//m_Unit  点与点之间的单位值
    {
    switch(nChar)
    {
    case 37:
    x1 = P_Star.x + Val;
    break;
    case 38:
    y1 = P_Star.y + Val;
    break;
    case 39:
    x1 = P_Star.x + Val;
    break;
    case 40:
    y1 = P_Star.y + Val;
    break;
    default:
    x1 = P_Star.x;
    y1 = P_Star.y; } int m_x1 = x1*m_Unit  - (int)((m_Unit) / 5);
    int m_y1 = y1*m_Unit - (int)((m_Unit) / 5);
    int m_x2 = x1*m_Unit + (int)((m_Unit) / 5);
    int m_y2 = y1*m_Unit + (int)((m_Unit) / 5);
    CPen pen;//(PS_SOLID, 2, RGB(255,255,128));
    pen.CreatePen(PS_SOLID, (int)((m_Unit + 1 )), RGB(255,255,128));

    HPEN poldPen = (HPEN)pDC->SelectObject (&pen);// pDC->SetPixel(P_Star , RGB(255,255,128));
    //pDC->FillSolidRect(m_x1, m_y1, m_x2, m_y2, RGB(10,10,10));
    pDC->Arc(m_x1, m_y1, m_x2, m_y2, m_x2, P_Star.y, m_x2, P_Star.y); 

    pDC->SelectObject(&poldPen);
    // //pDC->DrawEdge(
    }void CPointRay::SetUpLine(CLine * pLine)
    {
    LineToUp = pLine;
    }void CPointRay::SetDownLine(CLine * pLine)
    {
    LineToDown = pLine;
    }CLine * CPointRay::GetUpLine()
    {
    return LineToUp;
    }CLine * CPointRay::GetDownLine()
    {
    return LineToDown;
    }//================================================================================================================CLine::CLine()
    {
    m_x1 = 0;
    m_x2 = 0;
    m_y1 = 0;
    m_y2 = 0;
    x1 = 0;
    y1 = 0;}CLine::~CLine()
    {}
    /*
    void CLine::GetFrame(CPoint *pStar, CPoint *pEnd)
    {
    pStar = NULL;
    pEnd  = NULL;
    }
    */
    void CLine::DrawLine(CDC *pDC, int m_Unit, int nChar, int Val)//m_Unit  点与点之间的单位值
    {
    switch(nChar)
    {
    case 37:
    x1 = P_Star.x + Val;
    x2 = P_End.x + Val;
    break;
    case 38:
    y1 = P_Star.y + Val;
    y2 = P_End.y + Val;
    break;
    case 39:
    x1 = P_Star.x + Val;
    x2 = P_End.x + Val;
    break;
    case 40:
    y1 = P_Star.y + Val;
    y2 = P_End.y + Val;
    break;
    default:
    x1 = P_Star.x;
    y1 = P_Star.y;
    x2 = P_End.x;
    y2 = P_End.y; }
    CPen pen;//(PS_SOLID, 2, RGB(255,255,128));
    pen.CreatePen(PS_SOLID, 1, RGB(255,255,128));

    HPEN poldPen = (HPEN)pDC->SelectObject (&pen); pDC->MoveTo(x1*m_Unit, y1*m_Unit);
    pDC->LineTo(x2*m_Unit,  y2*m_Unit); pDC->SelectObject(&poldPen);
    //pDC->DrawEdge(
    }//================================================================================================================CControl::CControl()
    {
    m_x1 = 0;
    m_x2 = 0;
    m_y1 = 0;
    m_y2 = 0;
    x1 = 0;
    y1 = 0;}CControl::~CControl()
    {}void CControl::DrawControl(CDC *pDC, int m_Unit, int nChar, int Val)//m_Unit  点与点之间的单位值
    {
    ///////////////////////////////////////////////////////////////////////////////////

    switch(nChar)
    {
    case 37:
    x1 = P_Star.x + Val;
    break;
    case 38:
    y1 = P_Star.y + Val;
    break;
    case 39:
    x1 = P_Star.x + Val;
    break;
    case 40:
    y1 = P_Star.y + Val;
    break;
    default:
    x1 = P_Star.x;
    y1 = P_Star.y; } m_x1 = x1*m_Unit - ( 8 * m_Unit + (m_Unit / 2) );
    m_y1 = y1*m_Unit - m_Unit  ;
    m_x2 = x1*m_Unit + ( 7 * m_Unit + (m_Unit / 2) );
    m_y2 = y1*m_Unit + m_Unit ;
    pDC->Rectangle(m_x1, m_y1, m_x2, m_y2);
    CBrush m_brushBackground;
    m_brushBackground.CreateSolidBrush(RGB(250, 250, 250)); ///创建位图画刷   
    CRect   rect;   
    rect.bottom = m_y2;
    rect.right  = m_x2;
    rect.top = m_y1;
    rect.left = m_x1; pDC->Rectangle(&rect);
    pDC->FillRect(&rect , &m_brushBackground);
    ////////////////////////////////////////////////////////////////////////////////
    CPointRay  m_pointRay;
    m_y1 = m_y2 + m_Unit;
    for(int i = 0; i < 16;i++)
    {
    CPen pen(PS_SOLID, 1, RGB(255,255,128));
    //pen.CreatePen(PS_SOLID, 1, RGB(255,255,128));

    HPEN poldPen = (HPEN)pDC->SelectObject (&pen); m_x2 = m_x1 + i * (m_Unit);
    pDC->MoveTo(m_x2, m_y1);
    pDC->LineTo(m_x2, m_y2);
    pDC->SelectObject(&poldPen); m_pointRay.SetCoord(m_x1, m_y1);
    //m_pointRay.SetCoord_Y(m_y1);
    m_pointRay.DrawPoint(pDC,m_Unit, nChar , Val);
    } //pDC->DrawEdge(
    }void  CControl::GetFrame(CPoint * pStar, CPoint * pEnd)
    { pStar->x = P_Star.x - 8;
    pStar->y = P_Star.y - 1; pEnd->x = P_Star.x + 7;
    pEnd->y = P_Star.y + 2;
    return;
    }void CShape::SetEndPoint(const int x, const int y)
    {
    P_End.x = x;
    P_End.y = y;
    }void CShape::SetEndPoint(const CPoint * p)
    {
    P_End = *p;
    }
    void CPointRay::_conn::SetUpLine(CLine *pLine)
    {}
      

  7.   

    我在网上查的,一般是说指针没有初始化,但我每个指针都有初始化,至于指针越界,我也是这样怀疑的,但始终找不到相关代码,因为我的每一个即将压入的对象指针都是在push_back前才new的
      

  8.   

    我调试到系统库里,竟然是这里出的错,
    文件名:AFXMEM.CPP函数名:void* __cdecl operator new(size_t nSize)出错代码行:pResult = _malloc_dbg(nSize, _NORMAL_BLOCK, NULL, 0);
      

  9.   

    release版,放第一个器件就报错了
      

  10.   

    我检查了,错误一直只出现在push_back这个函数上
      

  11.   

    快点阿  最好跨平台、开源,支持linux我现在就等这个出来
    每次使用autoCAD都要切换到瘟到死windows server2003
      

  12.   

     m_spArr还有其他的相关操作吗
      

  13.   

    CShape *pSP = NULL; for(vector<CShape *>::const_iterator it=m_spArr.begin(); it!=m_spArr.end(); ++it)
    { pSP = (CShape *)(* it);
    if(pSP->m_DrawOrNot)
    {
    switch(pSP->GetType())
    {
    case 1:
    ((CPointRay *)(pSP))->DrawPoint(pDC, m_nDefaultThickness *10, m_nChar, nChangVal);
    break;
    case 2:
    ((CControl *)(pSP))->DrawControl(pDC, m_nDefaultThickness *10, m_nChar, nChangVal);
    break;
    case 3:
    ((CLine *)(pSP))->DrawLine(pDC, m_nDefaultThickness *10, m_nChar, nChangVal);
    break; }
    } }
    pSP = NULL;
    这是读取以后绘制操作
    m_spArr.clear();
    删除操作
    还有一个删除操作跟读取类似
    然后就是push_back
    再没有别的操作了