void CocaDocumentManager::onAuiPaneClose( wxAuiManagerEvent& event ) { COCA_DEBUG_INFO( "CocaDocumentManager::OnAuiPaneClose " << event.GetPane() << "; " << event.CanVeto() ); if ( !GetCurrentDocument() ) { return; } wxAuiPaneInfo* info = event.GetPane(); wxList& views = GetCurrentDocument()->GetViews(); wxList::iterator it; for ( it = views.begin(); it != views.end(); ++it ) { CocaView* view = coca::staticCast<CocaView*>( *it ); if ( view->getPane() == info->window ) { if ( view->Close( false ) ) { delete view; } else { event.Veto(); } return; } } event.Skip(); // no related view found, skip event }
void CTinyCadView::OnSpecialNet() { // Get rid of any drawing tool GetCurrentDocument()->SelectObject(new CDrawEditItem(GetCurrentDocument())); // Get the file in which to save the network TCHAR szFile[256]; _tcscpy_s(szFile,GetDocument()->GetPathName()); TCHAR* ext = _tcsrchr(szFile,'.'); if (!ext) { _tcscpy_s(szFile,_T("output.net")); } else { size_t remaining_space = &szFile[255] - ext + 1; _tcscpy_s(ext, remaining_space, _T(".net")); } CDlgPCBExport dlg; dlg.m_Filename = szFile; if (dlg.DoModal() != IDOK) return; // Generate the net list file CNetList netlist; netlist.m_prefix_references = dlg.m_Prefix; netlist.WriteNetListFile( dlg.m_type, static_cast<CTinyCadMultiDoc*>(GetDocument()), dlg.m_Filename ); // Now open the netlist for the user CTinyCadApp::EditTextFile( dlg.m_Filename ); }
void CTinyCadView::OnSpecialCreatespicefile() { // Get rid of any drawing tool GetCurrentDocument()->SelectObject(new CDrawEditItem(GetCurrentDocument())); // Get the file in which to save the network TCHAR szFile[256]; _tcscpy_s(szFile,GetDocument()->GetPathName()); TCHAR* ext = _tcsrchr(szFile,'.'); if (!ext) { _tcscpy_s(szFile,_T("output.net")); } else { size_t remaining_space = &szFile[255] - ext + 1; _tcscpy_s(ext, remaining_space, _T(".net")); } CFileDialog dlg( FALSE, _T("*.net"), szFile, OFN_HIDEREADONLY, _T("SPICE (*.net)|*.net|All files (*.*)|*.*||"), AfxGetMainWnd() ); if (dlg.DoModal() != IDOK) { return; } // Generate the SPICE file CNetList netlist; netlist.WriteSpiceFile( static_cast<CTinyCadMultiDoc*>(GetDocument()), dlg.GetPathName() ); }
// The scroll bar functions: // These control the horizontal and vertical scrolling of the window // (uses OnSize to track the window's size to stop the user being able to place text off the max size) void CTinyCadView::SetScroll(double NewX, double NewY, bool first) { CRect rect; int px, py; // How big is the current window? GetClientRect(rect); // Convert region into internal co-ords px = static_cast<int> (GetTransform().doubleDeScale(rect.right)); py = static_cast<int> (GetTransform().doubleDeScale(rect.bottom)); // Allow a 10% overlap CDPoint xlap = GetCurrentDocument()->GetDetails().GetOverlap(); int Xlap = static_cast<int> (xlap.x); int Ylap = static_cast<int> (xlap.y); // Now does this fit? if (px + NewX > GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().x + Xlap) NewX = GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().x + Xlap - px; if (py + NewY > GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().y + Ylap) NewY = GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().y + Ylap - py; if (NewX < -Xlap) NewX = -Xlap; if (NewY < -Ylap) NewY = -Ylap; if (first || GetTransform().GetOrigin() != CDPoint(NewX, NewY) || m_old_zoom_factor != GetTransform().GetZoomFactor()) { GetTransform().SetOriginX(NewX); GetTransform().SetOriginY(NewY); SCROLLINFO si; si.cbSize = sizeof(SCROLLINFO); si.nMin = 0; si.nMax = GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().x + Xlap * 2; si.nPage = static_cast<int> (GetTransform().doubleDeScale(rect.Width())); si.nPos = static_cast<int> (GetTransform().GetOrigin().x) + Xlap; si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL; SetScrollInfo(SB_HORZ, &si, TRUE); si.cbSize = sizeof(SCROLLINFO); si.nMin = 0; si.nMax = GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().y + Ylap * 2; si.nPage = static_cast<int> (GetTransform().doubleDeScale(rect.Height())); si.nPos = static_cast<int> (GetTransform().GetOrigin().y) + Ylap; si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL; SetScrollInfo(SB_VERT, &si, TRUE); if (hRuler != NULL) hRuler->RedrawWindow(); if (vRuler != NULL) vRuler->RedrawWindow(); Invalidate(); } m_old_zoom_factor = GetTransform().GetZoomFactor(); }
// The message handlers for the VScroll and HScroll messages void CTinyCadView::OnVScroll(UINT wParam, UINT pos, CScrollBar*) { CRect rect; int moveFast, moveSlow; int x = static_cast<int> (GetTransform().GetOrigin().x); int y = static_cast<int> (GetTransform().GetOrigin().y); GetClientRect(rect); int Width = static_cast<int> (GetTransform().doubleDeScale(rect.bottom)); moveFast = (Width << 4) / 20; moveSlow = (Width * 20) / 100; switch (wParam) { case SB_LINEUP: SetScroll(x, y - moveSlow); break; case SB_PAGEUP: SetScroll(x, y - moveFast); break; case SB_LINEDOWN: SetScroll(x, y + moveSlow); break; case SB_PAGEDOWN: SetScroll(x, y + moveFast); break; case SB_THUMBTRACK: case SB_THUMBPOSITION: { CDPoint xlap = GetCurrentDocument()->GetDetails().GetOverlap(); SetScroll(x, static_cast<int> (pos) - static_cast<int> (xlap.y)); } break; } }
void CTinyCadView::SetScrollCentre(CDPoint c) { CRect rect; CDPoint p; GetClientRect(rect); p = GetTransform().DeScale(GetCurrentDocument()->m_snap, CPoint(rect.right / 2, rect.bottom / 2)); SetScroll(GetTransform().GetOrigin().x + c.x - p.x, GetTransform().GetOrigin().y + c.y - p.y); }
// Track the size of the window void CTinyCadView::OnSize(UINT a, int cx, int cy) { CView::OnSize(a, cx, cy); if (IsWindowVisible()) { CTinyCadRegistry::SetMDIMaximize(GetParentFrame()->IsZoomed() != 0); } if (m_pDocument == NULL) return; CRect nSize; GetClientRect(nSize); if (vRuler != NULL) vRuler->OnNewSize(nSize); if (hRuler != NULL) hRuler->OnNewSize(nSize); if (GetCurrentDocument()) { SetScroll(GetTransform().GetOrigin().x, GetTransform().GetOrigin().y); } }
// Auto anotate the design void CTinyCadView::OnSpecialAnotate() { CDlgAnotateBox theDialog(this,theASetup); // Get rid of any drawing tool GetCurrentDocument()->SelectObject(new CDrawEditItem(GetCurrentDocument())); // Do the dialog int action = theDialog.DoModal(); if (action == IDC_REF_PAINTER) { theASetup = theDialog.v; GetCurrentDocument()->SelectObject(new CDrawRefPainter(GetCurrentDocument(), theASetup.startval )); return; } else if (action !=IDOK) { return; } theASetup = theDialog.v; // Set the busy icon SetCursor( AfxGetApp()->LoadStandardCursor( IDC_WAIT ) ); // Now add/remove references CDrawMethod *thisMethod; CSymbolRecord *thisSymbol; int value=0; int part=0; BOOL IsSet,IsMatch,MissingSymbols=FALSE; for (int i = 0; i < 2; i++) { int sheet = theASetup.all_sheets ? 0 : GetDocument()->GetActiveSheetIndex(); do { drawingIterator it = GetDocument()->GetSheet(sheet)->GetDrawingBegin(); while (it != GetDocument()->GetSheet(sheet)->GetDrawingEnd()) { CDrawingObject *pointer = *it; // Look for method objects if (pointer->GetType() == xMethodEx3) { thisMethod = (CDrawMethod *)pointer; thisSymbol = thisMethod->GetSymbolData(); // If there is no symbol then cannot modify this symbol! if (thisMethod->IsNoSymbol()) { MissingSymbols = TRUE; ++ it; continue; } // Has this symbol got a reference? IsSet = thisMethod->HasRef(); switch (theASetup.reference) { case 0: // All references IsMatch = TRUE; break; case 1: // Un-numbered references IsMatch = !thisMethod->HasRef(); break; case 2: // References that match... IsMatch = theASetup.matchval == thisSymbol->reference; break; } if (IsMatch) { // First pass - we remove references if necessary, // Second pass - we add refences back in... // if (i == 0) { // Remove any matching references (if necessary) if (IsSet && (theASetup.value!=1 || thisMethod->GetRefVal()>=theASetup.startval) ) { thisMethod->RemoveReference(); } } else { // Now add back any references if (theASetup.action == 0) { if (theASetup.reference != 1) { value = (theASetup.value == 0) ? 1 : theASetup.startval; } thisMethod->AddReference( value, theASetup.all_sheets ); } } } } ++ it; } ++ sheet; } while ( theASetup.all_sheets && sheet < GetDocument()->GetNumberOfSheets() ); } // Where there any missing symbols? if (MissingSymbols) Message(IDS_MISSMETH,MB_ICONEXCLAMATION); // Restore the correct cursor SetCursor( AfxGetApp()->LoadStandardCursor( IDC_ARROW ) ); // Ensure the window is re-drawn GetCurrentDocument()->SetModifiedFlag( TRUE ); Invalidate(); }
void CTinyCadView::OnSpecialBom() { // Get rid of any drawing tool GetCurrentDocument()->SelectObject(new CDrawEditItem(GetCurrentDocument())); // Get the file in which to save the network TCHAR szFile[256]; _tcscpy_s(szFile,GetDocument()->GetPathName()); TCHAR* ext = _tcsrchr(szFile,'.'); if (!ext) { _tcscpy_s(szFile,_T("output.txt")); } else { size_t remaining_space = &szFile[255] - ext + 1; _tcscpy_s(ext, remaining_space, _T(".txt")); } // Get the file name for the parts list CDlgBOMExport dlg(this); dlg.m_Filename = szFile; if (dlg.DoModal() != IDOK) { return; } FILE *theFile; errno_t err; err = _tfopen_s(&theFile, dlg.m_Filename,_T("w")); if ((theFile == NULL) || (err != 0)) { Message(IDS_CANNOTOPEN); return; } // Set the Busy icon SetCursor( AfxGetApp()->LoadStandardCursor( IDC_WAIT ) ); CBOMGenerator bom; bom.GenerateBomForDesign( dlg.m_All_Sheets != 0, dlg.m_All_Attrs != 0, dlg.m_Prefix != 0, dlg.m_Hierarchical != 0, GetDocument() ); // Now generate the output file bom.WriteToFile( theFile, dlg.m_type == 1 ); fclose(theFile); // Restore the normal cursor SetCursor( AfxGetApp()->LoadStandardCursor( IDC_ARROW ) ); // Where there any errors? if (bom.GetMissingRef()) Message(IDS_MISSREF); CTinyCadApp::EditTextFile( dlg.m_Filename ); }
void CocaDocumentManager::onAddSystemEditorView( wxCommandEvent& event ) { if ( GetCurrentDocument() ) { CreateView( GetCurrentDocument() ); } }
void CocaDocumentManager::onUpdateAddSystemEditorView( wxUpdateUIEvent& event ) { event.Enable( GetCurrentDocument() != 0 ); }
void CTinyCadView::OnDraw(CDC* pDC) { //CTinyCadDoc* pDoc = GetCurrentDocument(); CDC BitmapDC; CBitmap *old_bitmap = NULL; int selected; CRect client; if (pDC->IsKindOf(RUNTIME_CLASS(CPaintDC))) { client = static_cast<CPaintDC*> (pDC)->m_ps.rcPaint; } else { GetClientRect(&client); } // Are we going to use off-screen drawing? BOOL osb = !pDC->IsPrinting() && m_use_offscreen_drawing && CreateBitmap(*pDC, client.Width(), client.Height()); if (osb) { BitmapDC.CreateCompatibleDC(pDC); old_bitmap = BitmapDC.SelectObject(&m_bitmap); } { CContext dc(osb ? &BitmapDC : pDC, GetTransform(), this); CDPoint origin = GetTransform().GetOrigin(); if (osb) { CPoint point = CPoint(-client.left, -client.top); dc.SetPixelOffset(point); } if (pDC->IsPrinting()) { dc.SetBlack(CTinyCadRegistry::GetPrintBandW()); } CDPoint Start, End; CRect rect; GetClientRect(&rect); TransformSnap snap; snap.SetGridSnap(FALSE); Start = GetTransform().DeScale(snap, CPoint(rect.left, rect.top)); End = GetTransform().DeScale(snap, CPoint(rect.right, rect.bottom)); // Is any of this region in the off-page area? if (!pDC->IsPrinting()) { // Paint the region white if (pDC->IsPrinting()) { dc.SelectBrush(cWHITE); dc.SelectPen(PS_SOLID, 1, cWHITE); } else { COLORREF col = GetCurrentDocument()->GetOptions()->GetUserColor().Get(CUserColor::BACKGROUND); dc.SelectBrush(col, 0); dc.SelectPen(PS_SOLID, 1, col); } dc.Rectangle(CDRect(Start.x - 2, Start.y - 2, End.x + 2, End.y + 2)); dc.SelectBrush(cOFFPAGE); dc.SelectPen(PS_SOLID, 1, cOFFPAGE); if (End.x > GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().x) { CDPoint a = CDPoint(GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().x, 0); dc.Rectangle(CDRect(a.x, a.y, End.x, End.y)); } if (End.y > GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().y) { CDPoint a = CDPoint(Start.x, GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().y); dc.Rectangle(CDRect(a.x, a.y, End.x, End.y)); } if (Start.x < 0) dc.Rectangle(CDRect(0, Start.y, Start.x, End.y)); if (Start.y < 0) dc.Rectangle(CDRect(Start.x, 0, End.x, Start.y)); // Fill this region with a grid double grid = GetCurrentDocument()->m_snap.GetGrid(); double SGrid = dc.GetTransform().doubleScale(grid); if (GetCurrentDocument()->GetOptions()->ShowGrid() && SGrid > 10) { double x = dc.GetTransform().GetOrigin().x; double y = dc.GetTransform().GetOrigin().y; TransformSnap s = GetCurrentDocument()->m_snap; s.SetGridSnap(TRUE); x = s.Snap(x); y = s.Snap(y); for (double xp = x >= 0 ? x : 0; xp < End.x && xp < GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().x; xp += grid) { for (double yp = y >= 0 ? y : 0; yp < End.y && yp < GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().y; yp += grid) { dc.SetPixel(CDPoint(xp, yp), 0); } } } } Start -= CDPoint(10, 10); End += CDPoint(10, 10); GetCurrentDocument()->GetSelectBegin(); drawingIterator it = GetCurrentDocument()->GetDrawingBegin(); while (it != GetCurrentDocument()->GetDrawingEnd()) { CDrawingObject *obj = *it; selected = !pDC->IsPrinting() && GetCurrentDocument()->IsSelected(obj); paint_options options = selected ? draw_selected : draw_normal; if (!pDC->IsPrinting() || !obj->IsConstruction()) { if (pDC->IsPrinting() || obj->IsInside(Start.x, End.x, Start.y, End.y)) { obj->Paint(dc, options); } } ++it; } // Now draw the selectable object, so it stands out... CDrawingObject *obj = GetCurrentDocument()->GetSelectable(); if (obj != NULL && !GetCurrentDocument()->IsSelected(obj)) { paint_options options = draw_selectable; GetCurrentDocument()->GetSelectable()->Paint(dc, options); } // If only one item is selected then just draw its handles now if (GetCurrentDocument()->IsSingleItemSelected()) { GetCurrentDocument()->GetSingleSelectedItem()->PaintHandles(dc); } // if necessary turn back on the current object to be edited if (GetCurrentDocument()->GetEdit() != NULL) { //ATLTRACE2("TinyCadView::GetCurrentDocument->GetEdit->Paint(dc, draw_selected=%d)\n",draw_selected); GetCurrentDocument()->GetEdit()->Paint(dc, draw_selected); } // Draw the design details GetCurrentDocument()->Display(dc); } if (osb) { pDC->BitBlt(client.left, client.top, client.Width(), client.Height(), &BitmapDC, 0, 0, SRCCOPY); BitmapDC.SelectObject(old_bitmap); } }
Transform &CTinyCadView::GetTransform() { return m_Printing ? m_Printing_Transform : GetCurrentDocument()->GetTransform(); }
void CTinyCadView::OnSpecialCheck() { // Get rid of any drawing tool GetCurrentDocument()->SelectObject(new CDrawEditItem(GetCurrentDocument())); CDlgERCBox theDialog; static union { ErrorTest e; WORD i; } theErrorTest; theErrorTest.i = CTinyCadRegistry::GetInt("ERC", 0xffff); // Get the user's options theDialog.SetErrorTest(theErrorTest.e); if (theDialog.DoModal() != IDOK) { return; } theErrorTest.e = theDialog.GetErrorTest(); CTinyCadRegistry::Set("ERC",theErrorTest.i); // Set the Busy icon SetCursor( AfxGetApp()->LoadStandardCursor( IDC_WAIT ) ); // Generate the netlist CNetList netlist; netlist.m_follow_imports = false; CTinyCadMultiDoc *pDoc = static_cast<CTinyCadMultiDoc*>(GetDocument()); netlist.MakeNet( pDoc ); netCollection *nets = &netlist.m_nets; // Delete all the errors which are currently in the design theERCListBox.Close(); // GetCurrentDocument()->DeleteErrors(); theERCListBox.Open( pDoc ); int CurrentError = 0; // Scan the design for duplicated references if ((theErrorTest.e).DupRef) { std::set<CString> refs; CString last = ""; for (int i = 0; i < pDoc->GetNumberOfSheets(); i++) { drawingIterator it = pDoc->GetSheet(i)->GetDrawingBegin(); while (it != pDoc->GetSheet(i)->GetDrawingEnd()) { CDrawingObject *pointer = *it; if (pointer->GetType()==xMethodEx3) { CString ref = static_cast<CDrawMethod *>(pointer)->GetField(CDrawMethod::Ref); if (refs.find( ref ) != refs.end()) { // We have a duplicate... CString buffer; buffer.LoadString( ERR_DUPREF ); pDoc->GetSheet(i)->Add(new CDrawError(pDoc->GetSheet(i),static_cast<CDrawMethod *>(pointer)->GetFieldPos(CDrawMethod::Ref),CurrentError++)); theERCListBox.AddString(buffer); } else { refs.insert( ref ); } } ++ it; } } } // Scan netlist to determine the type of each net netCollection::iterator nit = nets->begin(); while (nit != nets->end()) { nodeVector::iterator nv_it = (*nit).second.begin(); int theNetType = nUnknown; CString lastPower = ""; int connections = 0; CDPoint pos; int sheet = 0; while (theNetType < ERR_BASE && nv_it != (*nit).second.end()) { CNetListNode& theNode = *nv_it; CDrawingObject* pObject = theNode.m_parent; if (pObject != NULL) { // Determine the type of this node int node_type = nUnknown; switch (pObject->GetType()) { case xPower: node_type = nPower; if (lastPower=="") { lastPower = static_cast<CDrawPower *>(pObject)->GetValue(); } else { if ( lastPower != static_cast<CDrawPower *>(pObject)->GetValue() ) { theNetType = ERR_POWER; node_type = nUnknown; break; } } connections ++; pos = pObject->m_point_a; sheet = theNode.m_sheet; break; case xNoConnect: node_type = 1; connections ++; pos = pObject->m_point_a; sheet = theNode.m_sheet; break; case xPin: case xPinEx: { CDrawPin *pPin = static_cast<CDrawPin*>( pObject ); switch(pPin->GetElec()) { case 0: // Input node_type = nInput; break; case 1: // Output node_type = nOutput; break; case 2: // Tristate node_type = nBiDir; break; case 3: // Open Collector node_type = nBiDir; break; case 4: // Passive node_type = nPassive; break; case 5: // Input/Output node_type = nBiDir; break; case 6: // Not Connected node_type = nNoConnect; break; } if (pPin->IsPower()) { node_type = nPower; } pos = pPin->GetActivePoint(theNode.m_pMethod); sheet = theNode.m_sheet; connections ++; } break; } theNetType = (node_type!=nUnknown) ? ErcTable[theNetType][node_type] : theNetType; } ++ nv_it; } int ErrorNumber = 0; if (connections == 1) { theNetType = ERR_UNCONNECT; } switch (theNetType) { case nUnknown: if (connections > 0) { ErrorNumber = ERR_UNCONNECTED; } break; case nInput: ErrorNumber = ERR_NOUTPUT; break; case nNoConnect: if (connections > 2) { theNetType = ERR_UNCONNECT; } break; default: ErrorNumber = theNetType; break; } // Is this error to be reported? switch (ErrorNumber) { case ERR_UNCONNECT: if (!((theErrorTest.e).UnConnect)) ErrorNumber = -1; break; case ERR_POWER: if (!((theErrorTest.e).Power)) ErrorNumber = -1; break; case ERR_NOCONNECT: if (!((theErrorTest.e).NoConnect)) ErrorNumber = -1; break; case ERR_NOUTPUT: if (!((theErrorTest.e).NoOutput)) ErrorNumber = -1; break; case ERR_DUPREF: if (!((theErrorTest.e).DupRef)) ErrorNumber = -1; break; case ERR_OUTPUT: if (!((theErrorTest.e).Output)) ErrorNumber = -1; break; case ERR_OUTPUTTOPWR: if (!((theErrorTest.e).OutputPwr)) ErrorNumber = -1; break; case ERR_UNCONNECTED: if (!((theErrorTest.e).UnConnected)) ErrorNumber = -1; break; case ERR_OUTPUTBIDIR: if (!((theErrorTest.e).Output)) ErrorNumber = -1; break; case ERR_POWERBIDIR: if (!((theErrorTest.e).OutputPwr)) ErrorNumber = -1; break; } if (ErrorNumber >= ERR_BASE) { CString buffer; buffer.LoadString( ErrorNumber ); pDoc->GetSheet(sheet-1)->Add(new CDrawError(pDoc->GetSheet(sheet-1),pos,CurrentError++)); theERCListBox.AddString(buffer); } ++ nit; } // Were any errors detected? if (CurrentError == 0) { CString buffer; buffer.LoadString( ERR_NOERROR ); theERCListBox.AddString(buffer); } // Set the normal icon SetCursor( AfxGetApp()->LoadStandardCursor( IDC_ARROW ) ); // Re-Draw the window Invalidate(); }