Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qucs_actions.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qucsactions.cpp
3  -----------------
4  begin : Sat May 1 2004
5  copyright : (C) 2004 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
7  ***************************************************************************/
8 
9 /* Copyright (C) 2014 Guilherme Brondani Torri <guitorri@gmail.com> */
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 #include <QtGui>
20 #include <QtCore>
21 #include <stdlib.h>
22 #include <limits.h>
23 
24 #include <QProcess>
25 #include <Q3PtrList>
26 
27 #include "main.h"
28 #include "qucs.h"
29 #include "schematic.h"
30 #include "textdoc.h"
31 #include "mouseactions.h"
32 #include "messagedock.h"
33 #include "components/ground.h"
34 #include "components/subcirport.h"
35 #include "components/equation.h"
36 #include "dialogs/matchdialog.h"
37 #include "dialogs/changedialog.h"
38 #include "dialogs/searchdialog.h"
39 #include "dialogs/librarydialog.h"
40 #include "dialogs/loaddialog.h"
41 #include "dialogs/importdialog.h"
42 #include "dialogs/packagedialog.h"
43 #include "module.h"
44 
45 // for editing component name on schematic
46 QRegExp Expr_CompProp;
47 QRegExpValidator Val_CompProp(Expr_CompProp, 0);
48 
49 // -----------------------------------------------------------------------
50 // This function is called from all toggle actions.
51 bool QucsApp::performToggleAction(bool on, QAction *Action,
52  pToggleFunc Function, pMouseFunc MouseMove, pMouseFunc2 MousePress)
53 {
54  editText->setHidden(true); // disable text edit of component property
55 
56  if(!on) {
57  MouseMoveAction = 0;
58  MousePressAction = 0;
61  activeAction = 0; // no action active
62  return false;
63  }
64 
65  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
66  do {
67  if(Function) if((Doc->*Function)()) {
68  Action->blockSignals(true);
69  Action->setOn(false); // release toolbar button
70  Action->blockSignals(false);
71  Doc->viewport()->update();
72  break;
73  }
74 
75  if(activeAction) {
76  activeAction->blockSignals(true); // do not call toggle slot
77  activeAction->setOn(false); // set last toolbar button off
78  activeAction->blockSignals(false);
79  }
80  activeAction = Action;
81 
82  MouseMoveAction = MouseMove;
83  MousePressAction = MousePress;
86 
87  } while(false); // to perform "break"
88 
89  Doc->viewport()->update();
90  view->drawn = false;
91  return true;
92 }
93 
94 // -----------------------------------------------------------------------
95 // Is called, when "set on grid" action is activated.
96 void QucsApp::slotOnGrid(bool on)
97 {
100 }
101 
102 // -----------------------------------------------------------------------
103 // Is called when the rotate toolbar button is pressed.
105 {
108 }
109 
110 // -----------------------------------------------------------------------
111 // Is called when the mirror toolbar button is pressed.
113 {
116 }
117 
118 // -----------------------------------------------------------------------
119 // Is called when the mirror toolbar button is pressed.
121 {
124 }
125 
126 // -----------------------------------------------------------------------
127 // Is called when the activate/deactivate toolbar button is pressed.
128 // It also comments out the selected text on a text document
129 // \todo update the status or tooltip message
131 {
132  TextDoc * Doc = (TextDoc *) DocumentTab->currentPage ();
133  if (isTextDocument (Doc)) {
134  //TODO Doc->clearParagraphBackground (Doc->tmpPosX);
135  Doc->commentSelected ();
136 
137  editActivate->blockSignals (true);
138  editActivate->setOn (false); // release toolbar button
139  editActivate->blockSignals (false);
140  }
141  else
145 }
146 
147 // ------------------------------------------------------------------------
148 // Is called if "Delete"-Button is pressed.
150 {
151  TextDoc *Doc = (TextDoc*)DocumentTab->currentPage();
152  if(Doc->inherits("QPlainTextEdit")) {
153  Doc->viewport()->setFocus();
154  //Doc->del();
155  Doc->textCursor().deleteChar();
156 
157  editDelete->blockSignals(true);
158  editDelete->setOn(false); // release toolbar button
159  editDelete->blockSignals(false);
160  }
161  else
164 }
165 
166 // -----------------------------------------------------------------------
167 // Is called if "Wire"-Button is pressed.
168 void QucsApp::slotSetWire(bool on)
169 {
172 }
173 
174 // -----------------------------------------------------------------------
176 {
179 }
180 
181 // -----------------------------------------------------------------------
183 {
186 }
187 
188 // -----------------------------------------------------------------------
189 // Is called, when "move component text" action is activated.
191 {
194 }
195 
196 // -----------------------------------------------------------------------
197 // Is called, when "Zoom in" action is activated.
198 void QucsApp::slotZoomIn(bool on)
199 {
200  TextDoc *Doc = (TextDoc*)DocumentTab->currentPage();
201  if(Doc->inherits("QPlainTextEdit")) {
202  Doc->zoomBy(1.5f);
203  magPlus->blockSignals(true);
204  magPlus->setOn(false);
205  magPlus->blockSignals(false);
206  }
207  else
210 }
211 
212 
214 {
215  select->setChecked(true);
216 }
217 
218 // -----------------------------------------------------------------------
219 // Is called when the select toolbar button is pressed.
220 void QucsApp::slotSelect(bool on)
221 {
222  QWidget *w = DocumentTab->currentPage();
223  if(w->inherits("QPlainTextEdit")) {
224  ((TextDoc*)w)->viewport()->setFocus();
225  select->blockSignals(true);
226  select->setOn(true);
227  select->blockSignals(false);
228  return;
229  }
230 
231  // goto to insertWire mode if ESC pressed during wiring
232  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
236  Doc->viewport()->update();
237  view->drawn = false;
238 
239  select->blockSignals(true);
240  select->setOn(false);
241  select->blockSignals(false);
242  return;
243  }
244 
248  }
249 }
250 
251 // -----------------------------------------------------------------------
253 {
254  // get the current document
255  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
256 
257  // if the current document is a text document paste in
258  // the contents of the clipboard as text
259  if(Doc->inherits("QPlainTextEdit"))
260  {
261  ((TextDoc*)Doc)->viewport()->setFocus();
262  ((TextDoc*)Doc)->paste();
263 
264  editPaste->blockSignals(true);
265  editPaste->setOn(false); // release toolbar button
266  editPaste->blockSignals(false);
267  return;
268  }
269  // if it's not a text doc, prevent the user from editing
270  // while we perform the paste operation
271  editText->setHidden(true);
272 
273  if(!on)
274  {
275  MouseMoveAction = 0;
276  MousePressAction = 0;
277  MouseReleaseAction = 0;
279  activeAction = 0; // no action active
280  if(view->drawn) Doc->viewport()->update();
281  return;
282  }
283 
284  if(!view->pasteElements(Doc))
285  {
286  editPaste->blockSignals(true); // do not call toggle slot
287  editPaste->setOn(false); // set toolbar button off
288  editPaste->blockSignals(false);
289  return; // if clipboard empty
290  }
291 
292  if(activeAction)
293  {
294  activeAction->blockSignals(true); // do not call toggle slot
295  activeAction->setOn(false); // set last toolbar button off
296  activeAction->blockSignals(false);
297  }
299 
300  view->drawn = false;
302  view->movingRotated = 0;
303  MousePressAction = 0;
304  MouseReleaseAction = 0;
306 }
307 
308 // -----------------------------------------------------------------------
310 {
311  TextDoc * Doc = (TextDoc *) DocumentTab->currentPage ();
312  Doc->viewport()->setFocus ();
313  //TODO Doc->clearParagraphBackground (Doc->tmpPosX);
314  Doc->insertSkeleton ();
315 
316  //int x, y;
317  //Doc->getCursorPosition (&x, &y);
318  //x = Doc->textCursor().blockNumber();
319  //y = Doc->textCursor().columnNumber();
320  Doc->slotCursorPosChanged();
321 }
322 
323 // -----------------------------------------------------------------------
324 // Is called when the mouse is clicked upon the equation toolbar button.
326 {
327  editText->setHidden(true); // disable text edit of component property
328  MouseReleaseAction = 0;
330 
331  if(!on) {
332  MouseMoveAction = 0;
333  MousePressAction = 0;
334  activeAction = 0; // no action active
335  return;
336  }
337  if(activeAction) {
338  activeAction->blockSignals(true); // do not call toggle slot
339  activeAction->setOn(false); // set last toolbar button off
340  activeAction->blockSignals(false);
341  }
343 
344  if(view->selElem)
345  delete view->selElem; // delete previously selected component
346 
347  view->selElem = new Equation();
348 
349  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
350  if(view->drawn) Doc->viewport()->update();
351  view->drawn = false;
354 }
355 
356 // -----------------------------------------------------------------------
357 // Is called when the mouse is clicked upon the ground toolbar button.
359 {
360  editText->setHidden(true); // disable text edit of component property
361  MouseReleaseAction = 0;
363 
364  if(!on) {
365  MouseMoveAction = 0;
366  MousePressAction = 0;
367  activeAction = 0; // no action active
368  return;
369  }
370  if(activeAction) {
371  activeAction->blockSignals(true); // do not call toggle slot
372  activeAction->setOn(false); // set last toolbar button off
373  activeAction->blockSignals(false);
374  }
376 
377  if(view->selElem)
378  delete view->selElem; // delete previously selected component
379 
380  view->selElem = new Ground();
381 
382  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
383  if(view->drawn) Doc->viewport()->update();
384  view->drawn = false;
387 }
388 
389 // -----------------------------------------------------------------------
390 // Is called when the mouse is clicked upon the port toolbar button.
392 {
393  editText->setHidden(true); // disable text edit of component property
394  MouseReleaseAction = 0;
396 
397  if(!on) {
398  MouseMoveAction = 0;
399  MousePressAction = 0;
400  activeAction = 0; // no action active
401  return;
402  }
403  if(activeAction) {
404  activeAction->blockSignals(true); // do not call toggle slot
405  activeAction->setOn(false); // set last toolbar button off
406  activeAction->blockSignals(false);
407  }
409 
410  if(view->selElem)
411  delete view->selElem; // delete previously selected component
412 
413  view->selElem = new SubCirPort();
414 
415  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
416  if(view->drawn) Doc->viewport()->update();
417  view->drawn = false;
420 }
421 
422 // --------------------------------------------------------------
423 // Is called, when "Undo"-Button is pressed.
425 {
426  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
427  if(Doc->inherits("QPlainTextEdit")) {
428  ((TextDoc*)Doc)->viewport()->setFocus();
429  ((TextDoc*)Doc)->undo();
430  return;
431  }
432 
433  editText->setHidden(true); // disable text edit of component property
434 
435  Doc->undo();
436  Doc->viewport()->update();
437  view->drawn = false;
438 }
439 
440 // --------------------------------------------------------------
441 // Is called, when "Undo"-Button is pressed.
443 {
444  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
445  if(Doc->inherits("QPlainTextEdit")) {
446  ((TextDoc*)Doc)->viewport()->setFocus();
447  ((TextDoc*)Doc)->redo();
448  return;
449  }
450 
451  editText->setHidden(true); // disable text edit of component property
452 
453  Doc->redo();
454  Doc->viewport()->update();
455  view->drawn = false;
456 }
457 
458 // --------------------------------------------------------------
459 // Is called, when "Align top" action is activated.
461 {
462  editText->setHidden(true); // disable text edit of component property
463 
464  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
465  if(!Doc->aligning(0))
466  QMessageBox::information(this, tr("Info"),
467  tr("At least two elements must be selected !"));
468  Doc->viewport()->update();
469  view->drawn = false;
470 }
471 
472 // --------------------------------------------------------------
473 // Is called, when "Align bottom" action is activated.
475 {
476  editText->setHidden(true); // disable text edit of component property
477 
478  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
479  if(!Doc->aligning(1))
480  QMessageBox::information(this, tr("Info"),
481  tr("At least two elements must be selected !"));
482  Doc->viewport()->update();
483  view->drawn = false;
484 }
485 
486 // --------------------------------------------------------------
487 // Is called, when "Align left" action is activated.
489 {
490  editText->setHidden(true); // disable text edit of component property
491 
492  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
493  if(!Doc->aligning(2))
494  QMessageBox::information(this, tr("Info"),
495  tr("At least two elements must be selected !"));
496  Doc->viewport()->update();
497  view->drawn = false;
498 }
499 
500 // --------------------------------------------------------------
501 // Is called, when "Align right" action is activated.
503 {
504  editText->setHidden(true); // disable text edit of component property
505 
506  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
507  if(!Doc->aligning(3))
508  QMessageBox::information(this, tr("Info"),
509  tr("At least two elements must be selected !"));
510  Doc->viewport()->update();
511  view->drawn = false;
512 }
513 
514 // --------------------------------------------------------------
515 // Is called, when "Distribute horizontally" action is activated.
517 {
518  editText->setHidden(true); // disable text edit of component property
519 
520  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
521  Doc->distributeHorizontal();
522  Doc->viewport()->update();
523  view->drawn = false;
524 }
525 
526 // --------------------------------------------------------------
527 // Is called, when "Distribute vertically" action is activated.
529 {
530  editText->setHidden(true); // disable text edit of component property
531 
532  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
533  Doc->distributeVertical();
534  Doc->viewport()->update();
535  view->drawn = false;
536 }
537 
538 // --------------------------------------------------------------
539 // Is called, when "Center horizontally" action is activated.
541 {
542  editText->setHidden(true); // disable text edit of component property
543 
544  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
545  if(!Doc->aligning(4))
546  QMessageBox::information(this, tr("Info"),
547  tr("At least two elements must be selected !"));
548  Doc->viewport()->update();
549  view->drawn = false;
550 }
551 
552 // --------------------------------------------------------------
553 // Is called, when "Center vertically" action is activated.
555 {
556  editText->setHidden(true); // disable text edit of component property
557 
558  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
559  if(!Doc->aligning(5))
560  QMessageBox::information(this, tr("Info"),
561  tr("At least two elements must be selected !"));
562  Doc->viewport()->update();
563  view->drawn = false;
564 }
565 
566 // ---------------------------------------------------------------------
567 // Is called when the "select all" action is activated.
569 {
570  editText->setHidden(true); // disable text edit of component property
571 
572  QWidget *Doc = DocumentTab->currentPage();
573  if(Doc->inherits("QPlainTextEdit")) {
574  ((TextDoc*)Doc)->viewport()->setFocus();
575  //((TextDoc*)Doc)->selectAll(true);
576  ((TextDoc*)Doc)->selectAll();
577  }
578  else {
579  ((Schematic*)Doc)->selectElements(INT_MIN, INT_MIN, INT_MAX, INT_MAX, true);
580  ((Schematic*)Doc)->viewport()->update();
581  view->drawn = false;
582  }
583 }
584 
585 // ---------------------------------------------------------------------
586 // Is called when the "select markers" action is activated.
588 {
589  editText->setHidden(true); // disable text edit of component property
590 
591  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
592  Doc->selectMarkers();
593  Doc->viewport()->update();
594  view->drawn = false;
595 }
596 
597 
598 extern QString lastDirOpenSave; // to remember last directory and file
599 
600 // ------------------------------------------------------------------------
601 // Is called by slotShowLastMsg(), by slotShowLastNetlist() and from the
602 // component edit dialog.
603 void QucsApp::editFile(const QString& File)
604 {
605  if (QucsSettings.Editor.toLower() == "qucs" | QucsSettings.Editor.isEmpty())
606  {
607  // The Editor is 'qucs' or empty, open a net document tab
608  if (File.isEmpty()) {
610  }
611  else
612  {
613  editText->setHidden(true); // disable text edit of component property
614 
615  statusBar()->message(tr("Opening file..."));
616 
617  QFileInfo finfo(File);
618 
619  if(!finfo.exists())
620  statusBar()->message(tr("Opening aborted, file not found."), 2000);
621  else {
622  gotoPage(File);
623  lastDirOpenSave = File; // remember last directory and file
624  statusBar()->message(tr("Ready."));
625  }
626  }
627  }
628  else
629  {
630  // use an external editor
631  QString prog;
632  QStringList args;
633 
634  if (QucsSettings.Editor.toLower().contains("qucsedit")) {
635 
636 #ifdef __MINGW32__
637  prog = "qucsedit.exe";
638 #elif __APPLE__
639  prog = "qucsedit.app/Contents/MacOS/qucsedit";
640 #else
641  prog = "qucsedit";
642 #endif
643 
644  QFileInfo editor(QucsSettings.BinDir + prog);
645  prog = QDir::toNativeSeparators(editor.canonicalFilePath());
646  }
647  else { // user defined editor
648  QFileInfo editor(QucsSettings.Editor);
649  prog = QDir::toNativeSeparators(editor.canonicalFilePath());
650  }
651 
652  if (!File.isEmpty()) {
653  args << File;
654  }
655 
656  QProcess *QucsEditor = new QProcess();
657  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
658  env.insert("PATH", env.value("PATH") );
659  QucsEditor->setProcessEnvironment(env);
660 
661  qDebug() << "Command: " << prog << args.join(" ");
662 
663  QucsEditor->start(prog, args);
664 
665  if( !QucsEditor->waitForStarted(1000) ) {
666  QMessageBox::critical(this, tr("Error"), tr("Cannot start text editor! \n\n%1").arg(prog));
667  delete QucsEditor;
668  return;
669  }
670  qDebug() << QucsEditor->readAllStandardError();
671 
672  // to kill it before qucs ends
673  connect(this, SIGNAL(signalKillEmAll()), QucsEditor, SLOT(kill()));
674  }
675 }
676 
677 // ------------------------------------------------------------------------
678 // Is called to show the output messages of the last simulation.
680 {
681  editFile(QucsSettings.QucsHomeDir.filePath("log.txt"));
682 }
683 
684 // ------------------------------------------------------------------------
685 // Is called to show the netlist of the last simulation.
687 {
688  editFile(QucsSettings.QucsHomeDir.filePath("netlist.txt"));
689 }
690 
691 // ------------------------------------------------------------------------
692 // Is called to start the text editor.
694 {
695  editFile(QString(""));
696 }
697 
698 // ------------------------------------------------------------------------
699 // Is called to start the filter synthesis program.
701 {
702  QString prog;
703 
704 #ifdef __MINGW32__
705  prog = "qucsfilter.exe";
706 #elif __APPLE__
707  prog = "qucsfilter.app/Contents/MacOS/qucsfilter";
708 #else
709  prog = "qucsfilter";
710 #endif
711 
712  QProcess *QucsFilter = new QProcess();
713 
714  QucsFilter->setWorkingDirectory(QucsSettings.BinDir);
715  QucsFilter->start(prog);
716 
717  prog = QDir::toNativeSeparators(QucsSettings.BinDir+prog);
718  qDebug() << "Command :" << prog;
719 
720  if( !QucsFilter->waitForStarted(1000) ) {
721  QMessageBox::critical(this, tr("Error"),
722  tr("Cannot start filter synthesis program! \n\n%1").arg(prog));
723  delete QucsFilter;
724  return;
725  }
726 
727  // to kill it before qucs ends
728  connect(this, SIGNAL(signalKillEmAll()), QucsFilter, SLOT(kill()));
729 }
730 
731 // ------------------------------------------------------------------------
732 // Is called to start the transmission line calculation program.
734 {
735  QString prog;
736 #ifdef __MINGW32__
737  prog = "qucstrans.exe";
738 #elif __APPLE__
739  prog = "qucstrans.app/Contents/MacOS/qucstrans";
740 #else
741  prog = "qucstrans";
742 #endif
743  QProcess *QucsLine = new QProcess();
744 
745  QucsLine->setWorkingDirectory(QucsSettings.BinDir);
746  QucsLine->start(prog);
747 
748  prog = QDir::toNativeSeparators(QucsSettings.BinDir+prog);
749  qDebug() << "Command :" << prog;
750 
751  if( !QucsLine->waitForStarted(1000) ) {
752  QMessageBox::critical(this, tr("Error"),
753  tr("Cannot start line calculation program! \n\n%1").arg(prog));
754  delete QucsLine;
755  return;
756  }
757 
758  // to kill it before qucs ends
759  connect(this, SIGNAL(signalKillEmAll()), QucsLine, SLOT(kill()));
760 }
761 
762 // ------------------------------------------------------------------------
763 // Is called to start the component library program.
765 {
766  QString prog;
767 #ifdef __MINGW32__
768  prog = "qucslib.exe";
769 #elif __APPLE__
770  prog = "qucslib.app/Contents/MacOS/qucslib";
771 #else
772  prog = "qucslib";
773 #endif
774 
775  QProcess *QucsLibrary = new QProcess();
776 
777  QucsLibrary->setWorkingDirectory(QucsSettings.BinDir);
778  QucsLibrary->start(prog);
779 
780  prog = QDir::toNativeSeparators(QucsSettings.BinDir+prog);
781  qDebug() << "Command :" << prog;
782 
783  if( !QucsLibrary->waitForStarted(1000) ) {
784 
785  QMessageBox::critical(this, tr("Error"),
786  tr("Cannot start library program! \n\n%1").arg(prog));
787  delete QucsLibrary;
788  return;
789  }
790 
791  // to kill it before qucs ends
792  connect(this, SIGNAL(signalKillEmAll()), QucsLibrary, SLOT(kill()));
793 }
794 
795 // --------------------------------------------------------------
796 // Is called to show a dialog for creating matching circuits.
798 {
799  MatchDialog *d = new MatchDialog(this);
800  d->exec();
801 }
802 
803 // ------------------------------------------------------------------------
804 // Is called to start the attenuator calculation program.
806 {
807  QString prog;
808 #ifdef __MINGW32__
809  prog = "qucsattenuator.exe";
810 #elif __APPLE__
811  prog = "qucsattenuator.app/Contents/MacOS/qucsattenuator";
812 #else
813  prog = "qucsattenuator";
814 #endif
815 
816  QProcess *QucsAtt = new QProcess();
817 
818  QucsAtt->setWorkingDirectory(QucsSettings.BinDir);
819  QucsAtt->start(prog);
820 
821  prog = QDir::toNativeSeparators(QucsSettings.BinDir+prog);
822  qDebug() << "Command :" << prog;
823 
824  if( !QucsAtt->waitForStarted(1000) ) {
825  QMessageBox::critical(this, tr("Error"),
826  tr("Cannot start attenuator calculation program! \n\n%1").arg(prog));
827  delete QucsAtt;
828  return;
829  }
830 
831  // to kill it before qucs ends
832  connect(this, SIGNAL(signalKillEmAll()), QucsAtt, SLOT(kill()));
833 }
834 // ------------------------------------------------------------------------
835 // Is called to start the resistor color code calculation program.
837 {
838  QString prog;
839 #ifdef __MINGW32__
840  prog = "qucsrescodes.exe";
841 #elif __APPLE__
842  prog = "qucsrescodes.app/Contents/MacOS/qucsrescodes";
843 #else
844  prog = "qucrescodes";
845 #endif
846 
847  QProcess *QucsRes = new QProcess();
848 
849  QucsRes->setWorkingDirectory(QucsSettings.BinDir);
850  QucsRes->start(prog);
851 
852  prog = QDir::toNativeSeparators(QucsSettings.BinDir+prog);
853  qDebug() << "Command :" << prog;
854 
855  if( !QucsRes->waitForStarted(1000) ) {
856  QMessageBox::critical(this, tr("Error"),
857  tr("Cannot start resistor color code calculation program! \n\n%1").arg(prog));
858  delete QucsRes;
859  return;
860  }
861 
862  // to kill it before qucs ends
863  connect(this, SIGNAL(signalKillEmAll()), QucsRes, SLOT(kill()));
864 }
865 // --------------------------------------------------------------
867 {
868  showHTML("index.html");
869 }
870 
871 // --------------------------------------------------------------
873 {
874  showHTML("start.html");
875 }
876 
877 // --------------------------------------------------------------
878 void QucsApp::showHTML(const QString& Page)
879 {
880 
881  QString prog;
882 #ifdef __MINGW32__
883  prog = "qucshelp.exe";
884 #elif __APPLE__
885  prog = "qucshelp.app/Contents/MacOS/qucshelp";
886 #else
887  prog = "qucshelp";
888 #endif
889 
890  QStringList com;
891  com << prog << Page;
892 
893  QProcess *QucsHelp = new QProcess();
894 
895  QucsHelp->setWorkingDirectory(QucsSettings.BinDir);
896  QucsHelp->start(com.join(" "));
897 
898  qDebug() << "Command :" << com.join(" ");
899  if( !QucsHelp->waitForStarted(1000) ) {
900  QMessageBox::critical(this, tr("Error"), tr("Cannot start qucshelp! \n\n%1").arg(com.join(" ")));
901  delete QucsHelp;
902  return;
903  }
904 
905  // to kill it before qucs ends
906  connect(this, SIGNAL(signalKillEmAll()), QucsHelp, SLOT(kill()));
907 }
908 
909 // ---------------------------------------------------------------------
910 // Is called when the find action is activated.
912 {
914 }
915 
916 // ---------------------------------------------------------------------
917 // Is called when the find-again action is activated.
919 {
920  SearchDia->searchText(true, 1);
921 }
922 
923 // --------------------------------------------------------------
925 {
926  QWidget *Doc = DocumentTab->currentPage();
927  if(Doc->inherits("QPlainTextEdit")) {
928  ((TextDoc*)Doc)->viewport()->setFocus();
929  SearchDia->initSearch(true);
930  }
931  else {
932  ChangeDialog *d = new ChangeDialog((Schematic*)Doc);
933  if(d->exec() == QDialog::Accepted) {
934  ((Schematic*)Doc)->setChanged(true, true);
935  ((Schematic*)Doc)->viewport()->update();
936  }
937  }
938 }
939 
940 // --------------------------------------------------------------
942 {
943  editText->setHidden(true); // disable text edit of component property
944 
945  if(ProjName.isEmpty()) {
946  QMessageBox::critical(this, tr("Error"), tr("No project open!"));
947  return;
948  }
949 
950 
951  QStringList List = QFileDialog::getOpenFileNames(this, tr("Select files to copy"),
952  lastDir.isEmpty() ? QString(".") : lastDir, QucsFileFilter);
953 
954  if(List.isEmpty()) {
955  statusBar()->message(tr("No files copied."), 2000);
956  return;
957  }
958 
959 
960  char *Buffer = (char*)malloc(0x10000);
961  if(!Buffer) return; // should never happen
962 
963  QStringList FileList = List; // make a copy as recommended by Qt
964  QStringList::Iterator it = FileList.begin();
965  QFileInfo Info(*it);
966  lastDir = Info.dirPath(true); // remember last directory
967 
968  // copy all files to project directory
969  int Num;
970  QFile origFile, destFile;
971  while(it != FileList.end()) {
972  Info.setFile(*it);
973  origFile.setName(*it);
974  destFile.setName(QucsSettings.QucsWorkDir.absPath() +
975  QDir::separator() + Info.fileName());
976 
977  if(!origFile.open(QIODevice::ReadOnly)) {
978  QMessageBox::critical(this, tr("Error"), tr("Cannot open \"%1\" !").arg(*it));
979  it++;
980  continue;
981  }
982 
983  if(destFile.exists())
984  if(QMessageBox::information(this, tr("Overwrite"),
985  tr("File \"%1\" already exists.\nOverwrite ?").arg(*it), QMessageBox::Yes,
986  QMessageBox::No|QMessageBox::Default|QMessageBox::Escape)
987  != QMessageBox::Yes) {
988  origFile.close();
989  it++;
990  continue;
991  }
992 
993  if(!destFile.open(QIODevice::WriteOnly)) {
994  QMessageBox::critical(this, tr("Error"), tr("Cannot create \"%1\" !").arg(*it));
995  origFile.close();
996  it++;
997  continue;
998  }
999 
1000  // copy data
1001  do {
1002  Num = origFile.readBlock(Buffer, 0x10000);
1003  if(Num < 0) {
1004  QMessageBox::critical(this, tr("Error"), tr("Cannot read \"%1\" !").arg(*it));
1005  break;
1006  }
1007  Num = destFile.writeBlock(Buffer, Num);
1008  if(Num < 0) {
1009  QMessageBox::critical(this, tr("Error"), tr("Cannot write \"%1\" !").arg(*it));
1010  break;
1011  }
1012  } while(Num == 0x10000);
1013 
1014  origFile.close();
1015  destFile.close();
1016  it++;
1017  }
1018 
1019  free(Buffer);
1020  readProjectFiles(); // re-read the content ListView
1021  statusBar()->message(tr("Ready."));
1022 }
1023 
1024 // -----------------------------------------------------------
1026 {
1027  if(!editText->isHidden()) return; // for edit of component property ?
1028 
1029  Q3PtrList<Element> movingElements;
1030  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
1031  int markerCount = Doc->copySelectedElements(&movingElements);
1032 
1033  if((movingElements.count() - markerCount) < 1) {
1034  if(markerCount > 0) { // only move marker if nothing else selected
1035  Doc->markerLeftRight(true, &movingElements);
1036  movingElements.clear();
1037  }
1038  else {
1039  if(Doc->scrollLeft(Doc->horizontalScrollBar()->lineStep()))
1040  Doc->scrollBy(-Doc->horizontalScrollBar()->lineStep(), 0);
1041  }
1042 
1043  Doc->viewport()->update();
1044  view->drawn = false;
1045  return;
1046  }
1047 
1048  view->moveElements(&movingElements, -Doc->GridX, 0); // move "GridX" to left
1049  view->MAx3 = 1; // sign for moved elements
1050  view->endElementMoving(Doc, &movingElements);
1051 }
1052 
1053 // -----------------------------------------------------------
1055 {
1056  if(!editText->isHidden()) return; // for edit of component property ?
1057 
1058  Q3PtrList<Element> movingElements;
1059  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
1060  int markerCount = Doc->copySelectedElements(&movingElements);
1061 
1062  if((movingElements.count() - markerCount) < 1) {
1063  if(markerCount > 0) { // only move marker if nothing else selected
1064  Doc->markerLeftRight(false, &movingElements);
1065  movingElements.clear();
1066  }
1067  else {
1068  if(Doc->scrollRight(-Doc->horizontalScrollBar()->lineStep()))
1069  Doc->scrollBy(Doc->horizontalScrollBar()->lineStep(), 0);
1070  }
1071 
1072  Doc->viewport()->update();
1073  view->drawn = false;
1074  return;
1075  }
1076 
1077  view->moveElements(&movingElements, Doc->GridX, 0); // move "GridX" to right
1078  view->MAx3 = 1; // sign for moved elements
1079  view->endElementMoving(Doc, &movingElements);
1080 }
1081 
1082 // -----------------------------------------------------------
1084 {
1085  if(!editText->isHidden()) { // for edit of component property ?
1086  if(view->MAx3 == 0) return; // edit component namen ?
1088  Property *pp = pc->Props.at(view->MAx3-1); // current property
1089  int Begin = pp->Description.find('[');
1090  if(Begin < 0) return; // no selection list ?
1091  int End = pp->Description.find(editText->text(), Begin); // current
1092  if(End < 0) return; // should never happen
1093  End = pp->Description.findRev(',', End);
1094  if(End < Begin) return; // was first item ?
1095  End--;
1096  int Pos = pp->Description.findRev(',', End);
1097  if(Pos < Begin) Pos = Begin; // is first item ?
1098  Pos++;
1099  if(pp->Description.at(Pos) == ' ') Pos++; // remove leading space
1100  editText->setText(pp->Description.mid(Pos, End-Pos+1));
1101  editText->selectAll();
1102  return;
1103  }
1104 
1105  Q3PtrList<Element> movingElements;
1106  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
1107  int markerCount = Doc->copySelectedElements(&movingElements);
1108 
1109  if((movingElements.count() - markerCount) < 1) {
1110  if(markerCount > 0) { // only move marker if nothing else selected
1111  Doc->markerUpDown(true, &movingElements);
1112  movingElements.clear();
1113  }
1114  else {
1115  if(Doc->scrollUp(Doc->verticalScrollBar()->lineStep()))
1116  Doc->scrollBy(0, -Doc->verticalScrollBar()->lineStep());
1117  }
1118 
1119  Doc->viewport()->update();
1120  view->drawn = false;
1121  return;
1122  }
1123 
1124  view->moveElements(&movingElements, 0, -Doc->GridY); // move "GridY" up
1125  view->MAx3 = 1; // sign for moved elements
1126  view->endElementMoving(Doc, &movingElements);
1127 }
1128 
1129 // -----------------------------------------------------------
1131 {
1132  if(!editText->isHidden()) { // for edit of component property ?
1133  if(view->MAx3 == 0) return; // edit component namen ?
1135  Property *pp = pc->Props.at(view->MAx3-1); // current property
1136  int Pos = pp->Description.find('[');
1137  if(Pos < 0) return; // no selection list ?
1138  Pos = pp->Description.find(editText->text(), Pos); // current list item
1139  if(Pos < 0) return; // should never happen
1140  Pos = pp->Description.find(',', Pos);
1141  if(Pos < 0) return; // was last item ?
1142  Pos++;
1143  if(pp->Description.at(Pos) == ' ') Pos++; // remove leading space
1144  int End = pp->Description.find(',', Pos);
1145  if(End < 0) { // is last item ?
1146  End = pp->Description.find(']', Pos);
1147  if(End < 0) return; // should never happen
1148  }
1149  editText->setText(pp->Description.mid(Pos, End-Pos));
1150  editText->selectAll();
1151  return;
1152  }
1153 
1154  Q3PtrList<Element> movingElements;
1155  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
1156  int markerCount = Doc->copySelectedElements(&movingElements);
1157 
1158  if((movingElements.count() - markerCount) < 1) {
1159  if(markerCount > 0) { // only move marker if nothing else selected
1160  Doc->markerUpDown(false, &movingElements);
1161  movingElements.clear();
1162  }
1163  else {
1164  if(Doc->scrollDown(-Doc->verticalScrollBar()->lineStep()))
1165  Doc->scrollBy(0, Doc->verticalScrollBar()->lineStep());
1166  }
1167 
1168  Doc->viewport()->update();
1169  view->drawn = false;
1170  return;
1171  }
1172 
1173  view->moveElements(&movingElements, 0, Doc->GridY); // move "GridY" down
1174  view->MAx3 = 1; // sign for moved elements
1175  view->endElementMoving(Doc, &movingElements);
1176 }
1177 
1178 // -----------------------------------------------------------
1179 // Is called if user clicked on component text of if return is
1180 // pressed in the component text QLineEdit.
1181 // In "view->MAx3" is the number of the current property.
1183 {
1184  QString s;
1185  QFont f = QucsSettings.font;
1186  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
1187  f.setPointSizeFloat( Doc->Scale * float(f.pointSize()) );
1188  editText->setFont(f);
1189 
1190  Property *pp = 0;
1192  if(!pc) return; // should never happen
1193  view->MAx1 = pc->cx + pc->tx;
1194  view->MAy1 = pc->cy + pc->ty;
1195 
1196  int z, n=0; // "n" is number of property on screen
1197  pp = pc->Props.first();
1198  for(z=view->MAx3; z>0; z--) { // calculate "n"
1199  if(!pp) { // should never happen
1200  editText->setHidden(true);
1201  return;
1202  }
1203  if(pp->display) n++; // is visible ?
1204  pp = pc->Props.next();
1205  }
1206 
1207  pp = 0;
1208  if(view->MAx3 > 0) pp = pc->Props.at(view->MAx3-1); // current property
1209  else s = pc->Name;
1210 
1211  if(!editText->isHidden()) { // is called the first time ?
1212  // no -> apply value to current property
1213  if(view->MAx3 == 0) { // component name ?
1214  Component *pc2;
1215  if(!editText->text().isEmpty())
1216  if(pc->Name != editText->text()) {
1217  for(pc2 = Doc->Components->first(); pc2!=0; pc2 = Doc->Components->next())
1218  if(pc2->Name == editText->text())
1219  break; // found component with the same name ?
1220  if(!pc2) {
1221  pc->Name = editText->text();
1222  Doc->setChanged(true, true); // only one undo state
1223  }
1224  }
1225  }
1226  else if(pp) { // property was applied
1227  if(pp->Value != editText->text()) {
1228  pp->Value = editText->text();
1229  Doc->recreateComponent(pc); // because of "Num" and schematic symbol
1230  Doc->setChanged(true, true); // only one undo state
1231  }
1232  }
1233 
1234  n++; // next row on screen
1235  (view->MAx3)++; // next property
1236  pp = pc->Props.at(view->MAx3-1); // search for next property
1237 
1238  Doc->viewport()->update();
1239  view->drawn = false;
1240 
1241  if(!pp) { // was already last property ?
1242  editText->setHidden(true);
1243  return;
1244  }
1245 
1246 
1247  while(!pp->display) { // search for next visible property
1248  (view->MAx3)++; // next property
1249  pp = pc->Props.next();
1250  if(!pp) { // was already last property ?
1251  editText->setHidden(true);
1252  return;
1253  }
1254  }
1255  }
1256 
1257  // avoid seeing the property text behind the line edit
1258  if(pp) // Is it first property or component name ?
1259  s = pp->Value;
1260  editText->setMinimumWidth(editText->fontMetrics().width(s)+4);
1261 
1262 
1263  Doc->contentsToViewport(int(Doc->Scale * float(view->MAx1 - Doc->ViewX1)),
1264  int(Doc->Scale * float(view->MAy1 - Doc->ViewY1)),
1265  view->MAx2, view->MAy2);
1266  editText->setReadOnly(false);
1267  if(pp) { // is it a property ?
1268  s = pp->Value;
1269  view->MAx2 += editText->fontMetrics().width(pp->Name+"=");
1270  if(pp->Description.find('[') >= 0) // is selection list ?
1271  editText->setReadOnly(true);
1272  Expr_CompProp.setPattern("[^\"]*");
1273  if(!pc->showName) n--;
1274  }
1275  else // it is the component name
1276  Expr_CompProp.setPattern("[\\w_]+");
1277  Val_CompProp.setRegExp(Expr_CompProp);
1278  editText->setValidator(&Val_CompProp);
1279 
1280  z = editText->fontMetrics().lineSpacing();
1281  view->MAy2 += n*z;
1282  editText->setText(s);
1283  editText->setPaletteBackgroundColor(QucsSettings.BGColor);
1284  editText->setFocus();
1285  editText->selectAll();
1286  editText->reparent(Doc->viewport(), 0, QPoint(view->MAx2, view->MAy2), true);
1287 }
1288 
1289 // -----------------------------------------------------------
1290 // Is called if the text of the property edit changed, to match
1291 // the width of the edit field.
1292 void QucsApp::slotResizePropEdit(const QString& t)
1293 {
1294  editText->resize(editText->fontMetrics().width(t)+4,
1295  editText->fontMetrics().lineSpacing());
1296 }
1297 
1298 // -----------------------------------------------------------
1300 {
1301  editText->setHidden(true); // disable text edit of component property
1302 
1303  if(ProjName.isEmpty()) {
1304  QMessageBox::critical(this, tr("Error"), tr("Please open project with subcircuits!"));
1305  return;
1306  }
1307 
1308  LibraryDialog *d = new LibraryDialog(this, ConSchematics);
1309  d->exec();
1310 }
1311 
1312 // -----------------------------------------------------------
1314 {
1315  editText->setHidden(true); // disable text edit of component property
1316 
1317  if(ProjName.isEmpty()) {
1318  QMessageBox::critical(this, tr("Error"), tr("Please open project first!"));
1319  return;
1320  }
1321 
1322  ImportDialog *d = new ImportDialog(this);
1323  if(d->exec() == QDialog::Accepted)
1324  readProjectFiles(); // re-read all project files
1325 }
1326 
1327 // -----------------------------------------------------------
1329 {
1330  editText->setHidden(true); // disable text edit of component property
1331 
1332  for(;;) {
1333  if(view->focusElement)
1334  if(view->focusElement->Type == isGraph)
1335  break;
1336 
1337  QMessageBox::critical(this, tr("Error"), tr("Please select a diagram graph!"));
1338  return;
1339  }
1340 
1341  /*QString s = Q3FileDialog::getSaveFileName(
1342  lastDir.isEmpty() ? QString(".") : lastDir,
1343  tr("CSV file")+" (*.csv);;" + tr("Any File")+" (*)",
1344  this, 0, tr("Enter an Output File Name"));
1345  */
1346  QString s = QFileDialog::getSaveFileName(this, tr("Enter an Output File Name"),
1347  lastDir.isEmpty() ? QString(".") : lastDir, tr("CSV file")+" (*.csv);;" + tr("Any File")+" (*)");
1348 
1349  if(s.isEmpty())
1350  return;
1351 
1352  QFileInfo Info(s);
1353  lastDir = Info.dirPath(true); // remember last directory
1354  if(Info.extension().isEmpty())
1355  s += ".csv";
1356 
1357  QFile File(s);
1358  if(File.exists())
1359  if(QMessageBox::information(this, tr("Info"),
1360  tr("Output file already exists!")+"\n"+tr("Overwrite it?"),
1361  tr("&Yes"), tr("&No"), 0,1,1))
1362  return;
1363 
1364  if(!File.open(QIODevice::WriteOnly)) {
1365  QMessageBox::critical(this, QObject::tr("Error"),
1366  QObject::tr("Cannot create output file!"));
1367  return;
1368  }
1369 
1370  QTextStream Stream(&File);
1371 
1372 
1373  DataX *pD;
1374  Graph *g = (Graph*)view->focusElement;
1375  // First output the names of independent and dependent variables.
1376  for(pD = g->cPointsX.first(); pD!=0; pD = g->cPointsX.next())
1377  Stream << '\"' << pD->Var << "\";";
1378  Stream << "\"r " << g->Var << "\";\"i " << g->Var << "\"\n";
1379 
1380 
1381  int n, m;
1382  double *py = g->cPointsY;
1383  int Count = g->countY * g->cPointsX.getFirst()->count;
1384  for(n = 0; n < Count; n++) {
1385  m = n;
1386  for(pD = g->cPointsX.first(); pD!=0; pD = g->cPointsX.next()) {
1387  Stream << *(pD->Points + m%pD->count) << ';';
1388  m /= pD->count;
1389  }
1390 
1391  Stream << *(py) << ';' << *(py+1) << '\n';
1392  py += 2;
1393  }
1394 
1395  File.close();
1396 }
1397 
1398 // ----------------------------------------------------------
1400 {
1401  editText->setHidden(true); // disable text edit of component property
1402 
1403  PackageDialog *d = new PackageDialog(this, true);
1404  d->exec();
1405 }
1406 
1407 // ----------------------------------------------------------
1409 {
1410  editText->setHidden(true); // disable text edit of component property
1411  PackageDialog *d = new PackageDialog(this, false);
1412  d->show();
1413  d->extractPackage();
1414  readProjects();
1415 }
1416 
1418 {
1419  //qDebug()<<QucsSettings.RecentDocs.at(num);
1420  gotoPage(QucsSettings.RecentDocs.at(num));
1423 }
1424 
1426 {
1427 
1428 
1429  QSignalMapper* mapper = new QSignalMapper(this);
1430  QList<QAction*> recent_docs;
1431 
1432  QString file;
1433  foreach (file,QucsSettings.RecentDocs) {
1434  recent_docs.prepend(new QAction(file,this));
1435  connect(recent_docs.first(),SIGNAL(triggered()),mapper,SLOT(map()));
1436  }
1437  recentfilesMenu->clear();
1438  recentfilesMenu->addActions(recent_docs);
1439 
1440  for (int i=0; i<recent_docs.count(); i++) {
1441  mapper->setMapping(recent_docs.at(i),(recent_docs.count() - 1)-i);
1442  }
1443 
1444  connect(mapper,SIGNAL(mapped(int)),this,SLOT(slotOpenRecent(int)));
1445 
1446  recentfilesMenu->insertSeparator();
1447  recentfilesMenu->addAction(tr("Clear list"),this,SLOT(slotClearRecentFiles()));
1448 
1449 }
1450 
1452 {
1453  QucsSettings.RecentDocs.clear();
1455 }
1456 
1457 
1462 {
1463  qDebug() << "slotLoadModule";
1464 
1465  LoadDialog *ld = new LoadDialog(this);
1466  ld->setApp(this);
1467 
1468  // fech list of _symbol.json
1469  // \todo fetch timestamp of VA, JSON, if VA newer, need to reload.
1470 
1471  QDir projDir = QucsSettings.QucsWorkDir.absolutePath();
1472 
1473  QStringList files;
1474  QString fileSuffix = "*_symbol.json";
1475 
1476  files = projDir.entryList(QStringList(fileSuffix),
1477  QDir::Files | QDir::NoSymLinks);
1478 
1479  // no JSON files or no a project?
1480  if (!files.size()){
1481  QMessageBox::critical(this, tr("Error"),
1482  tr("Symbol files not found in: %1\n\n"
1483  "Is the project open?\n"
1484  "Have you saved the Verilog-A symbols?")
1485  .arg(QString(projDir.absolutePath())));
1486  return;
1487  }
1488 
1489  // initialize dialog
1490 
1491  // pass list of potential symbol files
1492  ld->symbolFiles << files;
1493  ld->projDir = projDir;
1494  ld->initDialog();
1495 
1496  // \todo check what is already loaded, offer skip, reload
1497 
1498  //pass stuff to ld dialog
1499  // run, let user do the selections
1500 
1501  if (ld->exec() == QDialog::Accepted) {
1502 
1504 
1505  // dialog write new bitmap into JSON
1506  // load, unload, reload
1507  // inform if symbol changed
1508  // populate Module::vaComponents
1509  // vaComponents are selected with the dialog
1510  // dialog should populate acording to checkboxes
1511  // build vaComponents QMap
1512 
1513  // remove all modules before registering/loaded again
1514  // look for modules in the category,
1515  // \todo investigate if it is leaking objects somewhere
1516  QStringList remove;
1517  Q3DictIterator<Module> it( Module::Modules );
1518  for( ; it.current(); ++it ){
1519  if (it.current()->category == QObject::tr("verilog-a user devices"))
1520  remove << it.currentKey();
1521  }
1522  for (int i = 0; i < remove.size(); ++i){
1523  Module::Modules.remove(remove.at(i));
1524  }
1525 
1526  if (! Module::vaComponents.isEmpty()) {
1527  // Register whatever is in Module::vaComponents
1529 
1530  // update the combobox, set new category in view
1531  // pick up new category 'verilog-a user components' from `Module::category`
1532  //set new category into view
1533  QucsApp::fillComboBox(true);
1534  CompChoose->setCurrentItem(CompChoose->count()-1);
1535  slotSetCompView(CompChoose->count()-1);
1536 
1537  // icons of dynamically registered components ready to be dragged
1538  }
1539  }
1540 
1541  delete ld;
1542 
1543 }
1544 
1545 
1558 {
1559  qDebug() << "slotBuildModule";
1560 
1561  // reset message dock on entry
1562  messageDock->reset();
1563 
1564  messageDock->builderTabs->setTabIcon(0,QPixmap());
1565  messageDock->builderTabs->setTabIcon(1,QPixmap());
1566 
1567 
1568  QString make;
1569 
1570 #ifdef __MINGW32__
1571  make = "mingw32-make.exe"; // must be on the path!
1572 #else
1573  make = "make"; // must be on the path!
1574 #endif
1575 
1576  QDir prefix = QDir(QucsSettings.BinDir+"../");
1577 
1578  QDir include = QDir(QucsSettings.BinDir+"../include/qucs-core");
1579 
1580  QString workDir = QucsSettings.QucsWorkDir.absolutePath();
1581 
1582  // need to cd into project to make sure output is droped there?
1583  // need to cd - into previous location?
1584  QDir::setCurrent(workDir);
1585 
1586  QProcess *builder = new QProcess();
1587  builder->setProcessChannelMode(QProcess::MergedChannels);
1588  // get current va document
1589  QucsDoc *Doc = getDoc();
1590  QString vaModule = Doc->fileBase(Doc->DocName);
1591 
1592  QString admsXml = QucsSettings.AdmsXmlBinDir.canonicalPath();
1593 
1594 #ifdef __MINGW32__
1595  admsXml = QDir::toNativeSeparators(admsXml+"/"+"admsXml.exe");
1596 #else
1597  admsXml = QDir::toNativeSeparators(admsXml+"/"+"admsXml");
1598 #endif
1599 
1600  // admsXml emmits C++
1601  QStringList Arguments;
1602  Arguments << "-f" << QDir::toNativeSeparators(include.absoluteFilePath("va2cpp.makefile"))
1603  << QString("ADMSXML=%1").arg(admsXml)
1604  << QString("PREFIX=%1").arg(QDir::toNativeSeparators(prefix.absolutePath()))
1605  << QString("MODEL=%1").arg(vaModule);
1606 
1607  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
1608  env.insert("PATH", env.value("PATH") );
1609  builder->setProcessEnvironment(env);
1610 
1611  // prepend command to log
1612  QString cmdString = QString("%1 %2\n").arg(make, Arguments.join(" "));
1613  messageDock->admsOutput->appendPlainText(cmdString);
1614 
1615  qDebug() << "Command :" << make << Arguments.join(" ");
1616  builder->start(make, Arguments);
1617 
1618  // admsXml seems to communicate all via stdout, or is it because of make?
1619  QString vaStatus;
1620  if (!builder->waitForFinished()) {
1621  vaStatus = builder->errorString();
1622  qDebug() << "Make failed:" << vaStatus;
1623  }
1624  else {
1625  vaStatus = builder->readAll();
1626  qDebug() << "Make stdout" << vaStatus;
1627  }
1628 
1629  //build libs
1630  qDebug() << "\nbuild libs\n";
1631 
1632  Arguments.clear();
1633 
1634  Arguments << "-f" << QDir::toNativeSeparators(include.absoluteFilePath("cpp2lib.makefile"))
1635  << QString("PREFIX=\"%1\"").arg(QDir::toNativeSeparators(prefix.absolutePath()))
1636  << QString("PROJDIR=\"%1\"").arg(QDir::toNativeSeparators(workDir))
1637  << QString("MODEL=%1").arg(vaModule);
1638 
1639  // prepend command to log
1640  cmdString = QString("%1 %2\n").arg(make, Arguments.join(" "));
1641  messageDock->cppOutput->appendPlainText(cmdString);
1642 
1643  builder->start(make, Arguments);
1644 
1645  QString cppStatus;
1646 
1647  if (!builder->waitForFinished()) {
1648  cppStatus = builder->errorString();
1649  qDebug() << "Make failed:" << cppStatus;
1650  }
1651  else {
1652  cppStatus = builder->readAll();
1653  qDebug() << "Make output:" << cppStatus;
1654  }
1655  delete builder;
1656 
1657  // push make output to message dock
1658  messageDock->admsOutput->appendPlainText(vaStatus);
1659  messageDock->cppOutput->appendPlainText(cppStatus);
1660 
1661  // shot the message docks
1662  messageDock->msgDock->show();
1663 
1664 }
QDir AdmsXmlBinDir
Definition: main.h:67
bool scrollRight(int)
Definition: schematic.cpp:1963
void slotResizePropEdit(const QString &)
MessageDock * messageDock
Definition: qucs.h:192
void slotCursorRight()
void slotAddToProject()
void slotCenterVertical()
bool undo()
Definition: schematic.cpp:1578
void readProjectFiles()
Definition: qucs.cpp:1222
void slotCursorPosChanged()
TextDoc::slotCursorPosChanged update status bar with line:column.
Definition: textdoc.cpp:273
void slotInsertPort(bool)
void MPressElement(Schematic *, QMouseEvent *, float, float)
bool distributeVertical()
void slotClearRecentFiles()
void MMoveLabel(Schematic *, QMouseEvent *)
MouseActions::MMoveLabel Paints a label above the mouse cursor for "set wire label".
SearchDialog * SearchDia
Definition: qucs.h:82
void slotEditRedo()
QDir QucsWorkDir
Definition: main.h:65
int Type
Definition: element.h:152
QAction * setMarker
Definition: qucs.h:292
static QString fileBase(const QString &)
Definition: qucsdoc.cpp:111
void MMoveActivate(Schematic *, QMouseEvent *)
MouseActions::MMoveActivate Paints a crossed box mouse cursor to "(de)activate" components.
int countY
Definition: graph.h:74
Definition of the TextDoc class.
void slotZoomIn(bool)
bool gotoPage(const QString &)
Definition: qucs.cpp:1527
void showHTML(const QString &)
QComboBox * CompChoose
Definition: qucs.h:200
void slotShowLastNetlist()
bool aligning(int)
void slotInsertLabel(bool)
void slotInsertEquation(bool)
QAction * magPlus
Definition: qucs.h:292
int count
Definition: graph.h:53
void(MouseActions::* MouseMoveAction)(Schematic *, QMouseEvent *)
Definition: qucs.h:85
void MMoveMirrorY(Schematic *, QMouseEvent *)
MouseActions::MMoveMirrorX Paints rounded "mirror about y axis" mouse cursor.
void slotOnGrid(bool)
void slotCallLibrary()
void slotCallRes()
void MMoveElement(Schematic *, QMouseEvent *)
QFont font
Definition: main.h:46
float Scale
Definition: qucsdoc.h:58
Definition: graph.h:57
float zoomBy(float)
TextDoc::zoomBy increases/decreases the text font size.
Definition: textdoc.cpp:379
tQucsSettings QucsSettings
Definition: main.cpp:52
void MMoveMirrorX(Schematic *, QMouseEvent *)
MouseActions::MMoveMirrorX Paints rounded "mirror about x axis" mouse cursor.
void(MouseActions::* MousePressAction)(Schematic *, QMouseEvent *, float, float)
Definition: qucs.h:86
void MPressActivate(Schematic *, QMouseEvent *, float, float)
void MMoveOnGrid(Schematic *, QMouseEvent *)
MouseActions::MMoveOnGrid Paints a grid beside the mouse cursor, put "on grid" mode.
bool rotateElements()
Definition: schematic.cpp:1022
int tx
Definition: component.h:78
void slotDistribVert()
void MMoveMoveTextB(Schematic *, QMouseEvent *)
MouseActions::MMoveMoveTextB Paints mouse symbol for "move component text" mode.
The MessageDock class definiion.
void signalKillEmAll()
void(MouseActions::* pMouseFunc2)(Schematic *, QMouseEvent *, float, float)
Definition: qucs.h:59
QString Var
Definition: graph.h:50
void MPressLabel(Schematic *, QMouseEvent *, float, float)
void slotEditDelete(bool)
void slotChangeProps()
void MPressMirrorX(Schematic *, QMouseEvent *, float, float)
void slotMoveText(bool)
bool isEmpty() const
Definition: savedialog.cpp:130
void MMoveRotate(Schematic *, QMouseEvent *)
MouseActions::MMoveMirrorX Paints "rotate" mouse cursor.
static Q3Dict< Module > Modules
Definition: module.h:42
void endElementMoving(Schematic *, Q3PtrList< Element > *)
Definition: graph.h:47
Element * focusElement
Definition: mouseactions.h:51
void slotCallAtt()
void MPressDelete(Schematic *, QMouseEvent *, float, float)
bool activateSelectedComponents()
void MPressMarker(Schematic *, QMouseEvent *, float, float)
QString ProjName
Definition: qucs.h:74
QucsDoc * getDoc(int No=-1)
Definition: qucs.cpp:562
void slotSelectMarker()
QMenu * recentfilesMenu
Definition: qucs.h:268
QDir projDir
Definition: loaddialog.h:63
void initDialog()
Definition: loaddialog.cpp:59
QLineEdit * editText
Definition: qucs.h:81
QString Var
Definition: graph.h:75
QString BinDir
Definition: main.h:57
QPlainTextEdit * admsOutput
admsOutput holds the make output of running admsXml
Definition: messagedock.h:47
void slotEditFind()
int ViewY1
Definition: schematic.h:132
QAction * editRotate
Definition: qucs.h:292
QAction * insEquation
Definition: qucs.h:292
bool display
Definition: element.h:99
Definitions and declarations for the main application.
QAction * insWire
Definition: qucs.h:292
int ty
Definition: component.h:78
QString Value
Definition: element.h:97
void MPressWire1(Schematic *, QMouseEvent *, float, float)
MouseActions::MPressWire1 Is called if starting point of wire is pressed.
QAction * editDelete
Definition: qucs.h:292
QRegExpValidator Val_CompProp(Expr_CompProp, 0)
void slotInsertGround(bool)
int cx
Definition: element.h:153
void MMoveWire1(Schematic *, QMouseEvent *)
MouseActions::MMoveWire1 Paint hair cross for "insert wire" mode.
void MMovePaste(Schematic *, QMouseEvent *)
MouseActions::MMovePaste Moves components after paste from clipboard.
void slotAlignTop()
QString lastDir
Definition: main.cpp:55
int copySelectedElements(Q3PtrList< Element > *)
void slotEscape()
QMap< QString, QString > selectedComponents
Definition: loaddialog.h:65
Q3PtrList< Component > * Components
Definition: schematic.h:123
void reset()
MessageDock::reset clear the text and tab icons.
Definition: messagedock.cpp:76
void MReleaseSelect(Schematic *, QMouseEvent *)
void slotCursorDown()
QAction * insGround
Definition: qucs.h:292
Q3PtrList< Property > Props
Definition: component.h:72
void slotCursorLeft()
void slotLoadModule()
QucsApp::slotLoadModule launches the dialog to select dynamic modueles.
void slotHelpIndex()
bool mirrorYComponents()
Definition: schematic.cpp:1188
void slotCallFilter()
void MMoveMarker(Schematic *, QMouseEvent *)
MouseActions::MMoveMarker Paints a triangle above the mouse for "set marker on graph".
void slotEditPaste(bool)
void slotDistribHoriz()
void slotSetWire(bool)
void slotEditUndo()
bool scrollDown(int)
Definition: schematic.cpp:1912
void slotExtractPackage()
bool performToggleAction(bool, QAction *, pToggleFunc, pMouseFunc, pMouseFunc2)
QRegExp Expr_CompProp
void slotCenterHorizontal()
void MPressOnGrid(Schematic *, QMouseEvent *, float, float)
bool distributeHorizontal()
Element * selElem
Definition: mouseactions.h:50
QAction * insLabel
Definition: qucs.h:292
void slotBuildModule()
QucsApp::slotBuildModule runs admsXml, C++ compiler to build library.
QDockWidget * msgDock
Definition: messagedock.h:36
QAction * moveText
Definition: qucs.h:292
bool(Schematic::* pToggleFunc)()
Definition: qucs.h:57
void slotOpenRecent(int num)
QPlainTextEdit * cppOutput
cppOutput holds the make output of running a C++ compiler
Definition: messagedock.h:51
MouseActions * view
Definition: qucs.h:163
void slotSelectAll()
QAction * editMirrorY
Definition: qucs.h:292
int GridX
Definition: schematic.h:131
SubMap FileList
void MPressRotate(Schematic *, QMouseEvent *, float, float)
void(MouseActions::* MouseReleaseAction)(Schematic *, QMouseEvent *)
Definition: qucs.h:88
int ViewX1
Definition: schematic.h:132
void searchText(bool, int)
#define isGraph
Definition: element.h:115
QAction * editActivate
Definition: qucs.h:292
void slotShowLastMsg()
void slotImportData()
bool showName
Definition: component.h:79
QStringList RecentDocs
Definition: main.h:75
void initSearch(bool replace=false)
void slotCallMatch()
QDir QucsHomeDir
Definition: main.h:66
void slotApplyCompText()
void slotSelect(bool)
void slotExportGraphAsCsv()
static QMap< QString, QString > vaComponents
Definition: module.h:43
QString Name
Definition: element.h:97
void updateRecentFilesList(QString s)
Definition: qucs.cpp:3089
void slotCallLine()
QString QucsFileFilter
Definition: qucs.h:204
void slotAlignBottom()
void slotAlignLeft()
int GridY
Definition: schematic.h:131
void MMoveDelete(Schematic *, QMouseEvent *)
MouseActions::MMoveDelete Paints a cross under the mouse cursor to show the delete mode...
QTreeWidgetItem * ConSchematics
Definition: qucs.h:196
void fillComboBox(bool)
Definition: qucs.cpp:601
QTabWidget * DocumentTab
Definition: qucs.h:164
QString Name
Definition: component.h:80
void markerLeftRight(bool, Q3PtrList< Element > *)
QAction * activeAction
Definition: qucs.h:182
QAction * select
Definition: qucs.h:292
bool isTextDocument(QWidget *)
Definition: qucs.cpp:2764
QString Editor
Definition: main.h:56
void markerUpDown(bool, Q3PtrList< Element > *)
QTabWidget * builderTabs
Definition: messagedock.h:42
void insertSkeleton()
TextDoc::insertSkeleton adds a basic skeleton for type of text file.
Definition: textdoc.cpp:479
int cy
Definition: element.h:153
QAction * editPaste
Definition: qucs.h:292
void slotEditMirrorX(bool)
void editFile(const QString &)
void slotUpdateRecentFiles()
QString DocName
Definition: qucsdoc.h:51
void MPressMoveText(Schematic *, QMouseEvent *, float, float)
void(MouseActions::* MouseDoubleClickAction)(Schematic *, QMouseEvent *)
Definition: qucs.h:87
void slotInsertEntity()
The TextDoc class definition.
Definition: textdoc.h:49
QAction * onGrid
Definition: qucs.h:292
bool mirrorXComponents()
Definition: schematic.cpp:1119
QString lastDirOpenSave
Definition: qucs.cpp:1564
void slotEditMirrorY(bool)
void readProjects()
Definition: qucs.cpp:1107
static void registerDynamicComponents(void)
Definition: module.cpp:94
void slotSetCompView(int)
Definition: qucs.cpp:619
void setApp(QucsApp *a)
Definition: loaddialog.cpp:54
void slotEditRotate(bool)
bool pasteElements(Schematic *)
void slotGettingStarted()
void slotCreatePackage()
void commentSelected()
TextDoc::commentSelected toggles the comment of selected text See also QucsApp::slotEditActivate.
Definition: textdoc.cpp:424
void moveElements(Schematic *, int &, int &)
void slotAlignRight()
void slotCursorUp()
void slotCreateLib()
QStringList symbolFiles
Definition: loaddialog.h:62
void MPressMirrorY(Schematic *, QMouseEvent *, float, float)
double * Points
Definition: graph.h:52
QString Description
Definition: element.h:100
void recreateComponent(Component *)
void slotEditActivate(bool)
Q3PtrList< DataX > cPointsX
Definition: graph.h:71
Definition: ground.h:24
bool redo()
Definition: schematic.cpp:1631
void slotEditFindAgain()
void MDoubleClickSelect(Schematic *, QMouseEvent *)
bool scrollLeft(int)
Definition: schematic.cpp:1938
double * cPointsY
Definition: graph.h:72
QColor BGColor
Definition: main.h:48
void MMoveWire2(Schematic *, QMouseEvent *)
MouseActions::MMoveWire2 Paint wire as it is being drawn with mouse.
void MPressSelect(Schematic *, QMouseEvent *, float, float)
void MMoveZoomIn(Schematic *, QMouseEvent *)
MouseActions::MMoveZoomIn Paints symbol beside the mouse to show the "Zoom in" modus.
void slotCallEditor()
QAction * insPort
Definition: qucs.h:292
bool elementsOnGrid()
Definition: schematic.cpp:1685
bool scrollUp(int)
Definition: schematic.cpp:1887
void(MouseActions::* pMouseFunc)(Schematic *, QMouseEvent *)
Definition: qucs.h:58
void setChanged(bool, bool fillStack=false, char Op='*')
Definition: schematic.cpp:278
void slotTextNew()
Definition: qucs.cpp:1515
void slotSetMarker(bool)
void MPressZoomIn(Schematic *, QMouseEvent *, float, float)
QAction * editMirror
Definition: qucs.h:292