Ejemplo n.º 1
0
void Model::ClearLayers()
{
  for(vector<Layer *>::iterator i=layers.begin(); i != layers.end(); i++) {
    (*i)->Clear();
    delete *i;
  }
  layers.clear();
  Infill::clearPatterns();
  ClearPreview();
}
Ejemplo n.º 2
0
void TileScene::ClearAllTiles()
{
    ClearPreview();

    TileLayerItem *layer;
    foreach(layer, layers)
    {
        if(layer)
            layer->DestroyAllItems();
    }
}
Ejemplo n.º 3
0
void TileScene::ToggleSelectionMode(bool selection)
{
    QList<QGraphicsItem*> childrenList = items();

    //make every current item selectable
    if(selection)
    {
        for(int i = 0; i < childrenList.count(); i++)
            childrenList[i]->setFlag(QGraphicsItem::ItemIsSelectable);

        tileController->EndPaintOperation();
    }
    //make all items non-selectable
    else
    {
        for(int i = 0; i < childrenList.count(); i++)
            childrenList[i]->setFlag(QGraphicsItem::ItemIsSelectable, false);

        ClearPreview();
    }
}
Ejemplo n.º 4
0
void TileScene::RefreshPreview()
{
    ClearPreview();
    brushController->GetCurrentBrush()->Paint(lastPreviewSpot.x(), lastPreviewSpot.y(), tileController, true);
}
Ejemplo n.º 5
0
void Model::ConvertToGCode()
{
  if (is_calculating) {
    return;
  }
  is_calculating=true;

  // default:
  settings.SelectExtruder(0);

  Glib::TimeVal start_time;
  start_time.assign_current_time();

  gcode.clear();

  GCodeState state(gcode);

  Infill::clearPatterns();

  Vector3d printOffset  = settings.getPrintMargin();
  double   printOffsetZ = printOffset.z();

  // Make Layers
  lastlayer = NULL;


  Slice();

  //CleanupLayers();

  MakeShells();

  if (settings.get_boolean("Slicing","DoInfill") &&
      !settings.get_boolean("Slicing","NoTopAndBottom") &&
      (settings.get_double("Slicing","SolidThickness") > 0 ||
       settings.get_integer("Slicing","ShellCount") > 0))
    // not bridging when support
    MakeUncoveredPolygons( settings.get_boolean("Slicing","MakeDecor"),
			   !settings.get_boolean("Slicing","NoBridges") &&
			   !settings.get_boolean("Slicing","Support") );

  if (settings.get_boolean("Slicing","Support"))
    // easier before having multiplied uncovered bottoms
    MakeSupportPolygons(settings.get_double("Slicing","SupportWiden"));

  MakeFullSkins(); // must before multiplied uncovered bottoms

  MultiplyUncoveredPolygons();

  if (settings.get_boolean("Slicing","Skirt"))
    MakeSkirt();

  CalcInfill();

  if (settings.get_boolean("Raft","Enable"))
    {
      printOffset += Vector3d (settings.get_double("Raft","Size"), 0);
      MakeRaft (state, printOffsetZ); // printOffsetZ will have height of raft added
    }

  state.ResetLastWhere(Vector3d(0,0,0));
  uint count =  layers.size();

  m_progress->start (_("Making Lines"), count+1);

  state.AppendCommand(MILLIMETERSASUNITS,  false, _("Millimeters"));
  state.AppendCommand(ABSOLUTEPOSITIONING, false, _("Absolute Pos"));
  if (settings.get_boolean("Slicing","RelativeEcode"))
    state.AppendCommand(RELATIVE_ECODE, false, _("Relative E Code"));
  else
    state.AppendCommand(ABSOLUTE_ECODE, false, _("Absolute E Code"));

  bool cont = true;
  vector<PLine3> plines;
  bool farthestStart = settings.get_boolean("Slicing","FarthestLayerStart");
  Vector3d start = state.LastPosition();
  for (uint p=0; p<count; p++) {
    cont = (m_progress->update(p)) ;
    if (!cont) break;
    // cerr << "GCode layer " << (p+1) << " of " << count
    // 	 << " offset " << printOffsetZ
    // 	 << " have commands: " <<commands.size()
    // 	 << " start " << start <<  endl;;
    // try {
    if (farthestStart) {
      // Vector2d randstart = layers[p]->getRandomPolygonPoint();
      // start.set(randstart.x(), randstart.y());
      const Vector2d fartheststart = layers[p]->getFarthestPolygonPoint(start);
      start.set(fartheststart.x(), fartheststart.y());
    }
    layers[p]->MakePrintlines(start,
			      plines,
			      printOffsetZ,
			      settings);
    // } catch (Glib::Error &e) {
    //   error("GCode Error:", (e.what()).c_str());
    // }
    // if (layers[p]->getPrevious() != NULL)
    //   cerr << p << ": " <<layers[p]->LayerNo << " prev: "
    // 	   << layers[p]->getPrevious()->LayerNo << endl;
  }
  // do antiooze retract for all lines:
  Printlines::makeAntioozeRetract(plines, settings, m_progress);
  vector<Command> commands;
  //Printlines::getCommands(plines, settings, commands, m_progress);
  Printlines::getCommands(plines, settings, state, m_progress);

  //state.AppendCommands(commands, settings.Slicing.RelativeEcode);

  string GcodeTxt;
  if (cont)
    gcode.MakeText (GcodeTxt, settings, m_progress);
  else {
    ClearLayers();
    ClearGCode();
    ClearPreview();
  }

  // display whole layer if flat shapes
  // if (shapes.back()->dimensions() == 2)
  //   gcode.layerchanges.push_back(0);

  m_progress->stop (_("Done"));

  int h = (int)state.timeused/3600;
  int m = ((int)state.timeused%3600)/60;
  int s = ((int)state.timeused-3600*h-60*m);
  std::ostringstream ostr;
  ostr << _("Time Estimation: ") ;
  if (h>0) ostr << h <<_("h") ;
  ostr <<m <<_("m") <<s <<_("s") ;

  double gctime = gcode.GetTimeEstimation();
  if (abs(state.timeused - gctime) > 10) {
    h = (int)(gctime/3600);
    m = ((int)gctime)%3600/60;
    s = (int)(gctime)-3600*h-60*m;
    ostr << _(" / GCode Estimation: ");
    if (h>0) ostr << h <<_("h");
    ostr<< m <<_("m") << s <<_("s") ;
  }

  double totlength = gcode.GetTotalExtruded(settings.get_boolean("Slicing","RelativeEcode"));
  ostr << _(" - total extruded: ") << totlength << "mm";
  // TODO: ths assumes all extruders use the same filament diameter
  const double diam = settings.get_double("Extruder","FilamentDiameter");
  const double ccm = totlength * diam * diam / 4. * M_PI / 1000 ;
  ostr << " = " << ccm << "cm^3 ";
  ostr << "(ABS~" << ccm*1.08 << "g, PLA~" << ccm*1.25 << "g)";
  if (statusbar)
    statusbar->push(ostr.str());
  else
    cout << ostr.str() << endl;

  {
    Glib::TimeVal now;
    now.assign_current_time();
    const int time_used = (int) round((now - start_time).as_double()); // seconds
    cerr << "GCode generated in " << time_used << " seconds. " << GcodeTxt.size() << " bytes" << endl;
  }

  is_calculating=false;
  m_signal_gcode_changed.emit();
}
Ejemplo n.º 6
0
void Preview::Draw(SDL_Surface *screen)
{

    const Shape nextShape = System::GetNextPiece();
    const int nextRotation = System::GetNextRotation();
    const Tile_Color nextColor = static_cast<Tile_Color>(nextShape);
    const int keyTileX = 2;
    const int keyTileY = 1;

    //
    // Set Piece color.
    //

    ClearPreview();
    SetTileColor(keyTileX, keyTileY, nextColor);
    for (int i = 0; i < 3; i++)
    {
        SetTileColor(keyTileX + Piece_Data[nextShape].rotations[nextRotation].state[i][0],
                     keyTileY + Piece_Data[nextShape].rotations[nextRotation].state[i][1],
                     nextColor);
    }

    //
    // Fill puzzle surface with white.
    //

    SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 255, 255, 255));
    for (int x = 0; x < CONTROL_PREVIEW_SEG; x++)
    {
        for (int y = 0; y < CONTROL_PREVIEW_SEG; y++)
        {
            if (m_tiles[x][y] == WHITE)
            {
                continue;
            }

            const int squareWidth = screen->clip_rect.w / CONTROL_PREVIEW_SEG;
            const int squareHeight = screen->clip_rect.h / CONTROL_PREVIEW_SEG;
            const int xTileCord = x * squareWidth;
            const int yTileCord = y * squareWidth;

            SDL_Rect border_Rect;
            border_Rect.w = squareWidth + PUZZLE_TILE_BORDER;
            border_Rect.h = squareHeight + PUZZLE_TILE_BORDER;
            border_Rect.x = xTileCord - PUZZLE_TILE_BORDER;
            border_Rect.y = yTileCord - PUZZLE_TILE_BORDER;

            SDL_FillRect(screen, &border_Rect, SDL_MapRGB(screen->format, 0, 0, 0));

            SDL_Rect tile_Rect;
            tile_Rect.w = squareWidth - PUZZLE_TILE_BORDER;
            tile_Rect.h = squareHeight - PUZZLE_TILE_BORDER;
            tile_Rect.x = xTileCord;
            tile_Rect.y = yTileCord;

            SDL_FillRect(screen, &tile_Rect, SDL_MapRGB(screen->format, COLOR_Pieces[m_tiles[x][y]].r,
                                                                        COLOR_Pieces[m_tiles[x][y]].g,
                                                                        COLOR_Pieces[m_tiles[x][y]].b));
        }
    }
}
Ejemplo n.º 7
0
Preview::Preview(): m_x(0), m_y(0)
{
    ClearPreview();
}