/* --------------------------------------------------------------------------- * sets cursor grid with respect to grid offset values */ void SetGrid (Coord Grid, bool align) { char *grid_string; if (Grid >= 1 && Grid <= MAX_GRID) { if (align) { PCB->GridOffsetX = Crosshair.X % Grid; PCB->GridOffsetY = Crosshair.Y % Grid; } PCB->Grid = Grid; grid_string = pcb_g_strdup_printf ("%mr", Grid); if (grid_string) { AttributePut (PCB, "PCB::grid::size", grid_string); } g_free (grid_string); if (Settings.DrawGrid) { Redraw (); } } }
/* --------------------------------------------------------------------------- * load PCB * parse the file with enabled 'PCB mode' (see parser) * if successful, update some other stuff * * If revert is true, we pass "revert" as a parameter * to the HID's PCBChanged action. */ static int real_load_pcb (char *Filename, bool revert) { const char *unit_suffix, *grid_size; char *new_filename; PCBType *newPCB = CreateNewPCB (false); PCBType *oldPCB; #ifdef DEBUG double elapsed; clock_t start, end; start = clock (); #endif new_filename = strdup (Filename); oldPCB = PCB; PCB = newPCB; /* mark the default font invalid to know if the file has one */ newPCB->Font.Valid = false; /* new data isn't added to the undo list */ if (!ParsePCB (PCB, new_filename)) { RemovePCB (oldPCB); CreateNewPCBPost (PCB, 0); ResetStackAndVisibility (); /* update cursor location */ Crosshair.X = CLAMP (PCB->CursorX, 0, PCB->MaxWidth); Crosshair.Y = CLAMP (PCB->CursorY, 0, PCB->MaxHeight); /* update cursor confinement and output area (scrollbars) */ ChangePCBSize (PCB->MaxWidth, PCB->MaxHeight); /* enable default font if necessary */ if (!PCB->Font.Valid) { Message (_ ("File '%s' has no font information, using default font\n"), new_filename); PCB->Font.Valid = true; } /* clear 'changed flag' */ SetChangedFlag (false); PCB->Filename = new_filename; /* just in case a bad file saved file is loaded */ /* Use attribute PCB::grid::unit as unit, if we can */ unit_suffix = AttributeGet (PCB, "PCB::grid::unit"); if (unit_suffix && *unit_suffix) { const Unit *new_unit = get_unit_struct (unit_suffix); if (new_unit) Settings.grid_unit = new_unit; } AttributePut (PCB, "PCB::grid::unit", Settings.grid_unit->suffix); /* Use attribute PCB::grid::size as size, if we can */ grid_size = AttributeGet (PCB, "PCB::grid::size"); if (grid_size) { PCB->Grid = GetValue (grid_size, NULL, NULL); } sort_netlist (); set_some_route_style (); if (revert) hid_actionl ("PCBChanged", "revert", NULL); else hid_action ("PCBChanged"); #ifdef DEBUG end = clock (); elapsed = ((double) (end - start)) / CLOCKS_PER_SEC; gui->log ("Loading file %s took %f seconds of CPU time\n", new_filename, elapsed); #endif return (0); } PCB = oldPCB; hid_action ("PCBChanged"); /* release unused memory */ RemovePCB (newPCB); return (1); }