Beispiel #1
0
 /**
  * Select the primitive if one of its virtual point is in the specified rectangular region (given
  * in logical coordinates).
  *
  * @param px the x coordinate of the top left point.
  * @param py the y coordinate of the top left point.
  * @param w the width of the region
  * @param h the height of the region
  * @return true if at least a primitive has been selected
  */
 public boolean selectRect(int px, int py, int w, int h) {
   // Here is a trick: if there is at least one active layer,
   // distancePrimitive will return a value less than the maximum.
   SelectionActions sa = new SelectionActions(macro);
   EditorActions edt = new EditorActions(macro, sa, null);
   if (edt.distancePrimitive(0, 0) < Integer.MAX_VALUE) {
     return super.selectRect(px, py, w, h);
   } else {
     return false;
   }
 }
Beispiel #2
0
  /**
   * Gets the distance (in primitive's coordinates space) between a given point and the primitive.
   * When it is reasonable, the behaviour can be binary (polygons, ovals...). In other cases (lines,
   * points), it can be proportional.
   *
   * @param px the x coordinate of the given point.
   * @param py the y coordinate of the given point.
   * @return the distance in logical units.
   */
  public int getDistanceToPoint(int px, int py) {
    /* in the macro primitive, the the first virtual point represents
    the position of the reference point of the macro to be drawn. */

    int x1 = virtualPoint[0].x;
    int y1 = virtualPoint[0].y;
    int dt = Integer.MAX_VALUE;

    // Here we check if the given point lies inside the text areas

    if (checkText(px, py)) return 0;

    // If not, we need to see more throughly about the inners of the macro

    int vx = px - x1 + 100;
    int vy = py - y1 + 100;

    // This is a sort of inelegant code: we need to translate the position
    // given in the macro's coordinate system.

    if (m) {
      switch (o) {
        case 1:
          vx = py - y1 + 100;
          vy = px - x1 + 100;
          break;

        case 2:
          vx = px - x1 + 100;
          vy = -(py - y1) + 100;
          break;

        case 3:
          vx = -(py - y1) + 100;
          vy = -(px - x1) + 100;
          break;

        case 0:
          vx = -(px - x1) + 100;
          vy = py - y1 + 100;
          break;

        default:
          vx = 0;
          vy = 0;
          break;
      }
    } else {
      switch (o) {
        case 1:
          vx = py - y1 + 100;
          vy = -(px - x1) + 100;
          break;

        case 2:
          vx = -(px - x1) + 100;
          vy = -(py - y1) + 100;
          break;

        case 3:
          vx = -(py - y1) + 100;
          vy = px - x1 + 100;
          break;

        case 0:
          vx = px - x1 + 100;
          vy = py - y1 + 100;
          break;

        default:
          vx = 0;
          vy = 0;
          break;
      }
    }

    if (macroDesc == null)
      System.out.println("1-Unrecognized macro " + "WARNING this can be a programming problem...");
    else {
      SelectionActions sa = new SelectionActions(macro);
      EditorActions edt = new EditorActions(macro, sa, null);
      return Math.min(edt.distancePrimitive(vx, vy), dt);
    }
    return Integer.MAX_VALUE;
  }
Beispiel #3
0
  /**
   * Process the menu events.
   *
   * @param evt the event.
   * @param fff the frame in which the menu is present.
   */
  public void processMenuActions(ActionEvent evt, FidoFrame fff) {
    ExportTools et = fff.getExportTools();
    PrintTools pt = fff.getPrintTools();
    CircuitPanel cc = fff.cc;
    String arg = evt.getActionCommand();
    EditorActions edt = cc.getEditorActions();
    CopyPasteActions cpa = cc.getCopyPasteActions();
    ElementsEdtActions eea = cc.getContinuosMoveActions();
    SelectionActions sa = cc.getSelectionActions();
    ParserActions pa = cc.getParserActions();

    // Edit the FidoCadJ code of the drawing
    if (arg.equals(Globals.messages.getString("Define"))) {
      EnterCircuitFrame circuitDialog =
          new EnterCircuitFrame(fff, cc.getParserActions().getText(!cc.extStrict).toString());
      circuitDialog.setVisible(true);

      pa.parseString(new StringBuffer(circuitDialog.getStringCircuit()));
      cc.getUndoActions().saveUndoState();
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("LibraryUpdate"))) {
      // Update libraries
      fff.loadLibraries();
      fff.show();
    } else if (arg.equals(Globals.messages.getString("Circ_opt"))) {
      // Options for the current drawing
      fff.showPrefs();
    } else if (arg.equals(Globals.messages.getString("Layer_opt"))) {
      // Options for the layers
      DialogLayer layerDialog = new DialogLayer(fff, cc.dmp.getLayers());
      layerDialog.setVisible(true);

      // It is important that we force a complete recalculation of
      // all details in the drawing, otherwise the buffered setup
      // will not be responsive to the changes in the layer editing.

      cc.dmp.setChanged(true);
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Print"))) {
      // Print the current drawing
      pt.associateToCircuitPanel(cc);
      pt.printDrawing(fff);
    } else if (arg.equals(Globals.messages.getString("SaveName"))) {
      // Save with name
      fff.getFileTools().saveWithName(false);
    } else if (arg.equals(Globals.messages.getString("Save_split"))) {
      // Save with name, split non standard macros
      fff.getFileTools().saveWithName(true);
    } else if (arg.equals(Globals.messages.getString("Save"))) {
      // Save with the current name (if available)
      fff.getFileTools().save(false);
    } else if (arg.equals(Globals.messages.getString("New"))) {
      // New drawing
      fff.createNewInstance();
    } else if (arg.equals(Globals.messages.getString("Undo"))) {
      // Undo the last action
      cc.getUndoActions().undo();
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Redo"))) {
      // Redo the last action
      cc.getUndoActions().redo();
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("About_menu"))) {
      // Show the about menu
      DialogAbout d = new DialogAbout(fff);
      d.setVisible(true);
    } else if (arg.equals(Globals.messages.getString("Open"))) {
      // Open a file
      OpenFile openf = new OpenFile();
      openf.setParam(fff);
      SwingUtilities.invokeLater(openf);
      /*
          The following code would require a thread safe implementation
          of some of the inner classes (such as CircuitModel), which was
          indeed not the case... Now, yes!
      */
      /*Thread thread = new Thread(openf);
      thread.setDaemon(true);
      // Start the thread
      thread.start();*/

    } else if (arg.equals(Globals.messages.getString("Export"))) {
      // Export the current drawing
      et.launchExport(fff, cc, fff.getFileTools().openFileDirectory);
    } else if (arg.equals(Globals.messages.getString("SelectAll"))) {
      // Select all elements in the current drawing
      sa.setSelectionAll(true);
      // Even if the drawing is not changed, a repaint operation is
      // needed since all selected elements are rendered in green.
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Copy"))) {
      // Copy all selected elements in the clipboard
      cpa.copySelected(!cc.extStrict, false);
    } else if (arg.equals(Globals.messages.getString("Copy_split"))) {
      // Copy elements, splitting non standard macros
      cpa.copySelected(!cc.extStrict, true);
    } else if (arg.equals(Globals.messages.getString("Cut"))) {
      // Cut all the selected elements
      cpa.copySelected(!cc.extStrict, false);
      edt.deleteAllSelected(true);
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Mirror_E"))) {
      // Mirror all the selected elements
      if (eea.isEnteringMacro()) eea.mirrorMacro();
      else edt.mirrorAllSelected();
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Rotate"))) {
      // 90 degrees rotation of all selected elements
      if (eea.isEnteringMacro()) eea.rotateMacro();
      else edt.rotateAllSelected();
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Duplicate"))) {
      // Duplicate
      cpa.copySelected(!cc.extStrict, false);
      cpa.paste(cc.getMapCoordinates().getXGridStep(), cc.getMapCoordinates().getYGridStep());
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("DefineClipboard"))) {
      // Paste as a new circuit
      TextTransfer textTransfer = new TextTransfer();
      FidoFrame popFrame;
      if (cc.getUndoActions().getModified()) {
        popFrame = fff.createNewInstance();
      } else {
        popFrame = fff;
      }
      pa.parseString(new StringBuffer(textTransfer.getClipboardContents()));
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Paste"))) {
      // Paste some graphical elements
      cpa.paste(cc.getMapCoordinates().getXGridStep(), cc.getMapCoordinates().getYGridStep());
      fff.repaint();
    } else if (arg.equals(Globals.messages.getString("Close"))) {
      // Close the current window
      if (!fff.getFileTools().checkIfToBeSaved()) {
        return;
      }
      fff.setVisible(false);
      cc.getUndoActions().doTheDishes();
      fff.dispose();
      Globals.openWindows.remove(fff);

      --Globals.openWindowsNumber;

      if (Globals.openWindowsNumber < 1) System.exit(0);
    }
  }