Beispiel #1
0
bool ViewProgress::update (const double value, bool take_priority)
{
  // Don't allow progress to go backward
  if (value < m_bar_cur)
    return do_continue;

  m_bar_cur = CLAMP(value, 0, 1.0);
  m_bar->set_fraction(value / m_bar_max);
  ostringstream o;
  if(floor(value) != value && floor(m_bar_max) != m_bar_max)
    o.precision(1);
  else
    o.precision(0);
  o << fixed << value <<"/"<< m_bar_max;
  m_bar->set_text(o.str());
  if (to_terminal) {
    int perc = (int(m_bar->get_fraction()*100));
    cerr << m_label->get_label() << " " << o.str() << " -- " << perc << "%              \r";
  }

  if (value > 0) {
    Glib::TimeVal now;
    now.assign_current_time();
    const double used = (now - start_time).as_double(); // seconds
    const double total = used * m_bar_max  / value;
    const long left = (long)(total-used);
    m_label->set_label(label+" ("+timeleft_str(left)+")");
  }

  if (take_priority)
    while( gtk_events_pending () )
      gtk_main_iteration ();
  Gtk::Main::iteration(false);
  return do_continue;
}
Beispiel #2
0
bool Forest::animate(GlView & view)
{
    Glib::TimeVal delta = m_model.m_mainWindow.time();
    delta.subtract(m_lastUpdate);
    m_lastUpdate = m_model.m_mainWindow.time();
    m_cal3dModel.onUpdate(delta.as_double());
    return true;
}
Beispiel #3
0
// rearrange unselected shapes in random sequence
bool Model::AutoArrange(vector<Gtk::TreeModel::Path> &path)
{
  // all shapes
  vector<Shape*>   allshapes;
  vector<Matrix4d> transforms;
  objtree.get_all_shapes(allshapes, transforms);

  // selected shapes
  vector<Shape*>   selshapes;
  vector<Matrix4d> seltransforms;
  objtree.get_selected_shapes(path, selshapes, seltransforms);

  // get unselected shapes
  vector<Shape*>   unselshapes;
  vector<Matrix4d> unseltransforms;

  for(uint s=0; s < allshapes.size(); s++) {
    bool issel = false;
    for(uint ss=0; ss < selshapes.size(); ss++)
      if (selshapes[ss] == allshapes[s]) {
	issel = true; break;
      }
    if (!issel) {
      unselshapes.    push_back(allshapes[s]);
      unseltransforms.push_back(transforms[s]);
    }
  }

  // find place for unselected shapes
  int num = unselshapes.size();
  vector<int> rand_seq(num,1); // 1,1,1...
  partial_sum(rand_seq.begin(), rand_seq.end(), rand_seq.begin()); // 1,2,3,...,N

  Glib::TimeVal timeval;
  timeval.assign_current_time();
  srandom((unsigned long)(timeval.as_double()));
  random_shuffle(rand_seq.begin(), rand_seq.end()); // shuffle

  for(int s=0; s < num; s++) {
    int index = rand_seq[s]-1;
    // use selshapes as vector to fill up
    Vector3d trans = FindEmptyLocation(selshapes, seltransforms, unselshapes[index]);
    selshapes.push_back(unselshapes[index]);
    seltransforms.push_back(unseltransforms[index]); // basic transform, not shape
    selshapes.back()->transform3D.move(trans);
    CalcBoundingBoxAndCenter();
  }
  ModelChanged();
  return true;
}
Beispiel #4
0
void Shape::draw_geometry(uint max_triangles)
{

  bool listDraw = (max_triangles == 0); // not in preview mode
  bool haveList = gl_List >= 0;

  if (!listDraw && haveList) {
    if (gl_List>=0)
      glDeleteLists(gl_List,1);
    gl_List = -1;
    haveList = false;
  }
  if (listDraw && !haveList) {
    gl_List = glGenLists(1);
    glNewList(gl_List, GL_COMPILE);
  }
  if (!listDraw || !haveList) {
	uint step = 1;
	if (max_triangles>0) step = floor(triangles.size()/max_triangles);
	step = max((uint)1,step);

	glBegin(GL_TRIANGLES);
	for(size_t i=0;i<triangles.size();i+=step)
	{
		glNormal3dv(triangles[i].Normal);
		glVertex3dv(triangles[i].A);
		glVertex3dv(triangles[i].B);
		glVertex3dv(triangles[i].C);
	}
	glEnd();
  }
  if (listDraw && !haveList) {
    glEndList();
  }

  if (listDraw && gl_List >= 0) { // have stored list
    Glib::TimeVal starttime, endtime;
    if (!slow_drawing) {
      starttime.assign_current_time();
    }
    glCallList(gl_List);
    if (!slow_drawing) {
      endtime.assign_current_time();
      Glib::TimeVal usedtime = endtime-starttime;
      if (usedtime.as_double() > 0.2) slow_drawing = true;
    }
    return;
  }
}
Beispiel #5
0
void ViewProgress::stop (const char *label)
{
  if (to_terminal) {
    Glib::TimeVal now;
    now.assign_current_time();
    const int time_used = (int) round((now - start_time).as_double()); // seconds
    cerr << m_label->get_label() << " -- " << _(" done in ") << time_used << _(" seconds") << "       " << endl;
  }
  this->label = label;
  m_label->set_label (label);
  m_bar_cur = m_bar_max;
  m_bar->set_fraction(1.0);
  m_box->hide();
  Gtk::Main::iteration(false);
}
Beispiel #6
0
void Window::vComputeFrameskip(int _iRate)
{
    static Glib::TimeVal uiLastTime;
    static int iFrameskipAdjust = 0;

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

    if (m_bWasEmulating) {
        if (m_bAutoFrameskip) {
            Glib::TimeVal uiDiff = uiTime - uiLastTime;
            const int iWantedSpeed = 100;
            int iSpeed = iWantedSpeed;

            if (uiDiff != Glib::TimeVal(0, 0)) {
                iSpeed = (1000000 / _iRate) / (uiDiff.as_double() * 1000);
            }

            if (iSpeed >= iWantedSpeed - 2) {
                iFrameskipAdjust++;
                if (iFrameskipAdjust >= 3) {
                    iFrameskipAdjust = 0;
                    if (systemFrameSkip > 0) {
                        systemFrameSkip--;
                    }
                }
            } else {
                if (iSpeed < iWantedSpeed - 20) {
                    iFrameskipAdjust -= ((iWantedSpeed - 10) - iSpeed) / 5;
                } else if (systemFrameSkip < 9) {
                    iFrameskipAdjust--;
                }

                if (iFrameskipAdjust <= -4) {
                    iFrameskipAdjust = 0;
                    if (systemFrameSkip < 9) {
                        systemFrameSkip++;
                    }
                }
            }
        }
    } else {
        m_bWasEmulating = true;
    }

    uiLastTime = uiTime;
}
Beispiel #7
0
unsigned long Gobby::GSelector::get_timeout(const net6::socket& sock) const
{
	Glib::RecMutex::Lock lock(*m_mutex);
	map_type::const_iterator iter = m_map.find(&sock);

	// No timeout set for this socket
	if(iter == m_map.end() ) return 0;
	if(!iter->second.time_conn.connected() ) return 0;

	// Returns the remaining time for the timeout to be elapsed
	Glib::TimeVal val;
	val.assign_current_time();
	val -= iter->second.timeout_begin;

	unsigned long elapsed = (val.tv_sec * 1000 + val.tv_usec / 1000);
	if(elapsed >= iter->second.timeout) return 1;

	return iter->second.timeout - elapsed;
}
Beispiel #8
0
bool ViewProgress::restart (const char *label, double max)
{
  if (!do_continue) return false;
  //m_box->show();
  if (to_terminal) {
    Glib::TimeVal now;
    now.assign_current_time();
    const int time_used = (int) round((now - start_time).as_double()); // seconds
    cerr << m_label->get_label() << " -- " << _(" done in ") << time_used << _(" seconds") << "       " << endl;
  }
  m_bar_max = max;
  this->label = label;
  m_label->set_label (label);
  m_bar_cur = 0.0;
  m_bar->set_fraction(0.0);
  start_time.assign_current_time();
  //g_main_context_iteration(NULL,false);
  Gtk::Main::iteration(false);
  return true;
}
Beispiel #9
0
bool ASObject::waitUntilConstructed(unsigned long maxwait_ms)
{
	Mutex::Lock lock(constructionMutex);

	if(isConstructed())
		return true;

	// No need to loop over wait() because the construction state
	// will change only once from false to true.
	if(maxwait_ms==0)
	{
		constructionSignal.wait(constructionMutex);
		return true;
	}
	else
	{
		Glib::TimeVal waitEnd;
		waitEnd.assign_current_time();
		waitEnd.add_milliseconds(maxwait_ms);
		return constructionSignal.timed_wait(constructionMutex, waitEnd);
	}
}
Beispiel #10
0
void GCode::MakeText(string &GcodeTxt,
		     const Settings &settings,
		     ViewProgress * progress)
{
  string GcodeStart = settings.GCode.getStartText();
  string GcodeLayer = settings.GCode.getLayerText();
  string GcodeEnd   = settings.GCode.getEndText();

	double lastE = -10;
	double lastF = 0; // last Feedrate (can be omitted when same)
	Vector3d pos(0,0,0);
	Vector3d LastPos(-10,-10,-10);
	std::stringstream oss;

	Glib::Date date;
	date.set_time_current();
	Glib::TimeVal time;
	time.assign_current_time();
	GcodeTxt += "; GCode by Repsnapper, "+
	  date.format_string("%a, %x") +
	  //time.as_iso8601() +
	  "\n";

	GcodeTxt += "\n; Startcode\n"+GcodeStart + "; End Startcode\n\n";

	layerchanges.clear();
	if (progress) progress->restart(_("Collecting GCode"), commands.size());
	int progress_steps=(int)(commands.size()/100);
	if (progress_steps==0) progress_steps=1;

	for (uint i = 0; i < commands.size(); i++) {
	  char E_letter;
	  if (settings.Slicing.UseTCommand) // use first extruder's code for all extuders
	    E_letter = settings.Extruders[0].GCLetter[0];
	  else
	    E_letter = settings.Extruders[commands[i].extruder_no].GCLetter[0];
	  if (progress && i%progress_steps==0 && !progress->update(i)) break;

	  if ( commands[i].Code == LAYERCHANGE ) {
	    layerchanges.push_back(i);
	    if (GcodeLayer.length()>0)
	      GcodeTxt += "\n; Layerchange GCode\n" + GcodeLayer +
		"; End Layerchange GCode\n\n";
	  }

	  if ( commands[i].where.z() < 0 )  {
	    cerr << i << " Z < 0 "  << commands[i].info() << endl;
	  }
	  else {
	    GcodeTxt += commands[i].GetGCodeText(LastPos, lastE, lastF,
						 settings.Slicing.RelativeEcode,
						 E_letter,
						 settings.Hardware.SpeedAlways) + "\n";
	  }
	}

	GcodeTxt += "\n; End GCode\n" + GcodeEnd + "\n";

	buffer->set_text (GcodeTxt);

	// save zpos line numbers for faster finding
	buffer_zpos_lines.clear();
	uint blines = buffer->get_line_count();
	for (uint i = 0; i < blines; i++) {
	  const string line = getLineAt(buffer, i);
	  if (line.find("Z") != string::npos ||
	      line.find("z") != string::npos)
	    buffer_zpos_lines.push_back(i);
	}

	if (progress) progress->stop();

}
Beispiel #11
0
uint32_t systemGetClock()
{
    Glib::TimeVal time;
    time.assign_current_time();
    return time.as_double() * 1000;
}
Beispiel #12
0
int main(int argc, char* argv[]){
  // Some variables...
  int numberOfThreads;
  int duration;
  int i;
  Glib::Thread** threads;
  const char* config_file = NULL;
  int debug_level = -1;
  Arc::LogStream logcerr(std::cerr);

  // Process options - quick hack, must use Glib options later
  while(argc >= 3) {
    if(strcmp(argv[1],"-c") == 0) {
      config_file = argv[2];
      argv[2]=argv[0]; argv+=2; argc-=2;
    } else if(strcmp(argv[1],"-d") == 0) {
      debug_level=Arc::string_to_level(argv[2]);
      argv[2]=argv[0]; argv+=2; argc-=2;
    } else if(strcmp(argv[1],"-r") == 0) {
      alwaysReconnect=true; argv+=1; argc-=1;
    } else {
      break;
    };
  } 
  if(debug_level >= 0) {
    Arc::Logger::getRootLogger().setThreshold((Arc::LogLevel)debug_level);
    Arc::Logger::getRootLogger().addDestination(logcerr);
  }
  // Extract command line arguments.
  if (argc!=4){
    std::cerr << "Wrong number of arguments!" << std::endl
	      << std::endl
	      << "Usage:" << std::endl
	      << "perftest [-c config] [-d debug] [-r] url threads duration" << std::endl
	      << std::endl
	      << "Arguments:" << std::endl
	      << "url       The url of the service." << std::endl
	      << "threads   The number of concurrent requests." << std::endl
	      << "duration  The duration of the test in seconds." << std::endl
	      << "-c config The file containing client chain XML configuration with " << std::endl
              << "          'soap' entry point and HOSTNAME, PORTNUMBER and PATH " << std::endl
              << "           keyword for hostname, port and HTTP path of 'echo' service." << std::endl
	      << "-d debug   The textual representation of desired debug level. Available " << std::endl
              << "           levels: DEBUG, VERBOSE, INFO, WARNING, ERROR, FATAL." << std::endl
	      << "-r         If specified close connection and reconnect after " << std::endl
              << "           every request." << std::endl;
    exit(EXIT_FAILURE);
  }
  url_str = std::string(argv[1]);
  numberOfThreads = atoi(argv[2]);
  duration = atoi(argv[3]);

  // Start threads.
  run=true;
  finishedThreads=0;
  //Glib::thread_init();
  mutex=new Glib::Mutex;
  threads = new Glib::Thread*[numberOfThreads];
  for (i=0; i<numberOfThreads; i++)
    threads[i]=Glib::Thread::create(sigc::ptr_fun(sendRequests),true);

  // Sleep while the threads are working.
  Glib::usleep(duration*1000000);

  // Stop the threads
  run=false;
  while(finishedThreads<numberOfThreads)
    Glib::usleep(100000);

  // Print the result of the test.
  Glib::Mutex::Lock lock(*mutex);
  totalRequests = completedRequests+failedRequests;
  totalTime = completedTime+failedTime;
  std::cout << "========================================" << std::endl;
  std::cout << "URL: "
	    << url_str << std::endl;
  std::cout << "Number of threads: "
	    << numberOfThreads << std::endl;
  std::cout << "Duration: "
	    << duration << " s" << std::endl;
  std::cout << "Number of requests: "
	    << totalRequests << std::endl;
  std::cout << "Completed requests: "
	    << completedRequests << " ("
	    << Round(completedRequests*100.0/totalRequests)
	    << "%)" << std::endl;
  std::cout << "Failed requests: "
	    << failedRequests << " ("
	    << Round(failedRequests*100.0/totalRequests)
	    << "%)" << std::endl;
  std::cout << "Completed requests per second: "
            << Round(completedRequests/duration)
            << std::endl;
  std::cout << "Average response time for all requests: "
	    << Round(1000*totalTime.as_double()/totalRequests)
	    << " ms" << std::endl;
  if (completedRequests!=0)
    std::cout << "Average response time for completed requests: "
	      << Round(1000*completedTime.as_double()/completedRequests)
	      << " ms" << std::endl;
  if (failedRequests!=0)
    std::cout << "Average response time for failed requests: "
	      << Round(1000*failedTime.as_double()/failedRequests)
	      << " ms" << std::endl;
  std::cout << "========================================" << std::endl;

  return 0;
}
Beispiel #13
0
void GCode::MakeText(string &GcodeTxt, const string &GcodeStart, 
		     const string &GcodeLayer, const string &GcodeEnd,
		     bool RelativeEcode, 
		     ViewProgress * progress)
{
	double lastE = -10;
	double lastF = 0; // last Feedrate (can be omitted when same)
	Vector3d pos(0,0,0);
	Vector3d LastPos(-10,-10,-10);
	std::stringstream oss;

	Glib::Date date;
	date.set_time_current();
	Glib::TimeVal time;
	time.assign_current_time();
	GcodeTxt += "; GCode by Repsnapper, "+
	  date.format_string("%a, %x") +
	  //time.as_iso8601() +
	  "\n";

	GcodeTxt += "\n; Startcode\n"+GcodeStart + "; End Startcode\n\n";

	layerchanges.clear();

	progress->restart(_("Collecting GCode"),commands.size());
	int progress_steps=(int)(commands.size()/100);
	if (progress_steps==0) progress_steps=1;

	for (uint i = 0; i < commands.size(); i++) {
	  if (i%progress_steps==0) if (!progress->update(i)) break;

	  if ( commands[i].Code == LAYERCHANGE ) {
	    layerchanges.push_back(i);
	    if (GcodeLayer.length()>0)
	      GcodeTxt += "\n; Layerchange GCode\n" + GcodeLayer + 
		"; End Layerchange GCode\n\n"; 
	  }
	  
	  if ( commands[i].where.z() < 0 )  {
	    cerr << i << " Z < 0 "  << commands[i].info() << endl;
	  }
	  else {
	    GcodeTxt += commands[i].GetGCodeText(LastPos, lastE, lastF, RelativeEcode) + "\n";
	  }
	}

	GcodeTxt += "\n; End GCode\n" + GcodeEnd + "\n";

	buffer->set_text (GcodeTxt);

	// save zpos line numbers for faster finding
	buffer_zpos_lines.clear();
	uint blines = buffer->get_line_count();
	for (uint i = 0; i < blines; i++) {
	  const string line = getLineAt(buffer, i);
	  if (line.find("Z") != string::npos ||
	      line.find("z") != string::npos)
	    buffer_zpos_lines.push_back(i);
	}


	  // 	oss.str( "" );
	// 	switch(commands[i].Code)
	// 	{
	// 	case SELECTEXTRUDER:
	// 		oss  << "T0\n";
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		break;
	// 	case SETSPEED:
	// 		commands[i].where.z() = LastPos.z();
	// 		commands[i].e = lastE;
	// 	case ZMOVE:
	// 		commands[i].where.x() = LastPos.x();
	// 		commands[i].where.y() = LastPos.y();
	// 	case COORDINATEDMOTION:
	// 		if ((commands[i].where.x() != LastPos.x()) + 
	// 		    (commands[i].where.y() != LastPos.y()) +
	// 		    (commands[i].where.z() != LastPos.z()) != 0 &&
	// 		    AntioozeDistance != 0 && commands[i].e == lastE &&
	// 		    !Use3DGcode && AntioozeDistance != 0)
	// 		{
	// 			if (UseIncrementalEcode)
	// 			{
	// 				oss << "G1 E" << (lastE - AntioozeDistance) << "  F" << AntioozeSpeed << " ;antiooze retract\n";
	// 			}
	// 			else
	// 			{
	// 				oss << "G1 E" << -(AntioozeDistance) << "  F" << AntioozeSpeed << " ;antiooze retract\n";
	// 			}
	// 		}
	// 		oss  << "G1 ";
	// 		if(commands[i].where.x() != LastPos.x())
	// 			oss << "X" << commands[i].where.x() << " ";
	// 		if(commands[i].where.y() != LastPos.y())
	// 			oss << "Y" << commands[i].where.y() << " ";
	// 		if(commands[i].where.z() != LastPos.z())
	// 			oss << "Z" << commands[i].where.z() << " ";
	// 		if(commands[i].e != lastE)
	// 		{
	// 			if(UseIncrementalEcode)	// in incremental mode, the same is nothing
	// 				{
	// 				if(commands[i].e != lastE)
	// 					oss << "E" << commands[i].e << " ";
	// 				}
	// 			else
	// 				{
	// 				if(commands[i].e >= 0.0)
	// 					oss << "E" << commands[i].e << " ";
	// 				}
	// 		}
	// 		oss << "F" << commands[i].f;
	// 		if(commands[i].comment.length() != 0)
	// 			oss << " ;" << commands[i].comment << "\n";
	// 		else
	// 			oss <<  "\n";
	// 		if ((commands[i].where.x() != LastPos.x()) + 
	// 		    (commands[i].where.y() != LastPos.y()) +
	// 		    (commands[i].where.z() != LastPos.z()) != 0 &&
	// 		    AntioozeDistance != 0 &&
	// 		    commands[i].e == lastE  && 
	// 		    !Use3DGcode && AntioozeDistance != 0)
	// 		{
	// 			if (UseIncrementalEcode)
	// 			{
	// 				oss << "G1 E" << lastE << "  F" << AntioozeSpeed << " ;antiooze return\n";
	// 			}
	// 			else
	// 			{
	// 				oss << "G1 E" << AntioozeDistance << "  F" << AntioozeSpeed << " ;antiooze return\n";
	// 			}
	// 		}
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		if(commands[i].Code == ZMOVE && commands[i].where.z() != LastPos.z())
	// 		  add_text_filter_nan(GcodeLayer + "\n", GcodeTxt);
	// 		  //GcodeTxt += GcodeLayer + "\n";

	// 		LastPos = commands[i].where;
	// 		if( commands[i].e >= 0.0)
	// 			lastE = commands[i].e;
	// 		break;
	// 	case EXTRUDERON:
	// 	  // Dont switch extruder on/off right after eachother
	// 		if(i != 0 && commands[i-1].Code == EXTRUDEROFF) continue;
	// 		oss  << "M101\n";
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		break;
	// 	case EXTRUDEROFF:
	// 	  // Dont switch extruder on/off right after eachother
	// 		if(i != 0 && (i+1) < commands.size() && 
	// 		   commands[i+1].Code == EXTRUDERON) continue;	
	// 		// don't switch extruder off twize
	// 		if(i != 0 && (i+1) < commands.size() && 
	// 		   commands[i+1].Code == EXTRUDEROFF) continue;	
	// 		oss  << "M103\n";
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		break;
	// 	case COORDINATEDMOTION3D:
	// 		oss  << "G1 X" << commands[i].where.x() << " Y" << commands[i].where.y() << " Z" << commands[i].where.z();
	// 		oss << " F" << commands[i].f;
	// 		if(commands[i].comment.length() != 0)
	// 			oss << " ;" << commands[i].comment << "\n";
	// 		else
	// 			oss <<  "\n";
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		LastPos = commands[i].where;
	// 		break;
	// 	case RAPIDMOTION:
	// 		oss  << "G0 X" << commands[i].where.x() << " Y" << commands[i].where.y() << " Z" << commands[i].where.z()  << "\n";
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		LastPos = commands[i].where;
	// 		break;
	// 	case GOTO:
	// 		oss  << "G92";
	// 		if(commands[i].where.x() != LastPos.x() && commands[i].where.x() >= 0)
	// 		{
	// 			LastPos.x() = commands[i].where.x();
	// 			oss << " X" << commands[i].where.x();
	// 		}
	// 		if(commands[i].where.y() != LastPos.y() && commands[i].where.y() >= 0)
	// 		{
	// 			LastPos.y() = commands[i].where.y();
	// 			oss << " Y" << commands[i].where.y();
	// 		}
	// 		if(commands[i].where.z() != LastPos.z() && commands[i].where.z() >= 0)
	// 		{
	// 			LastPos.z() = commands[i].where.z();
	// 			oss << " Z" << commands[i].where.z();
	// 		}
	// 		if(commands[i].e != lastE && commands[i].e >= 0.0)
	// 		{
	// 			lastE = commands[i].e;
	// 			oss << " E" << commands[i].e;
	// 		}
	// 		oss <<  "\n";
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		break;
	// 	default:
	// 		break; // ignored CGCode
	// 	}
	// 	pos = commands[i].where;
	// cerr<< oss.str()<< endl;
	//}

}
Beispiel #14
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();
}
Beispiel #15
0
bool SimVoteWindow::loadConfiguration(std::string pass)
{
	bool loginOk = false;

	if (VotingCentersWrapper::getInstance()->isInstall())
	{
		VotingCenter votingCenter;
		VotingCentersWrapper::getInstance()->getInstallationVotingCenter(votingCenter);
		votingCenterName = votingCenter.getCode();
	}

	std::cout << "Center : " << votingCenterName << std::endl;

	loginOk = MachineOperationManager::getInstance()->authentication(votingCenterName, pass, true);

	//Load precalculate other info needed for the VM
	try
	{
		if(loginOk)

		{

		loginOk = false;

		electoralConfiguration->loadAllData();
		Smartmatic::SAES::Printing::VotePrintDocument::calculateMax(electoralConfiguration);

		std::string openingDateTime = electoralConfiguration->getVotingDevice()->getFirstVotingDevice().getOperation_modes().getOperation_mode()[0].getOpening_date_time();
		std::string closingDateTime = electoralConfiguration->getVotingDevice()->getFirstVotingDevice().getOperation_modes().getOperation_mode()[0].getClosing_date_time();

		Glib::TimeVal openingTime;
		Glib::TimeVal closingTime;

		openingTime.assign_from_iso8601(openingDateTime);
		double openingD = openingTime.as_double();

		closingTime.assign_from_iso8601(closingDateTime);
		double closingD = closingTime.as_double();

		Smartmatic::SAES::Security::Encryption::getInstance()->setMachineTime(openingD + (openingD + closingD)/2);

		Smartmatic::SAES::Voting::OperationStatus::Current()->init();
		Glib::ustring openingCode = Smartmatic::SAES::Voting::OperationStatus::Current()->getElectionStatusWrapper()->getOpeningCode();
		Smartmatic::System::GuidClass openCodeGUID = Smartmatic::System::GuidClass::Parse(openingCode);
		Smartmatic::SAES::Security::Encryption::getInstance()->setOpeningCode(openCodeGUID);

		//Clear previous language
		ElectionInstalationLanguages::getInstance()->clearLanguage();

		Smartmatic::SAES::Voting::Election::Languages::LanguageSequence & sequence (electoralConfiguration->getLanguages().getLanguage());

		for (Smartmatic::SAES::Voting::Election::Languages::LanguageIterator it = sequence.begin(); it != sequence.end(); ++it)
		{
			ElectionInstalationLanguages::getInstance()->addInstallationLanguages((*it));
			Smartmatic::SAES::Voting::SetLanguageFunctionality::setNewVotingLanguageByLanguageCountry(it->getLanguage(),it->getCountry());
			break;
		}


		loginOk = true;
		}
	}
	catch(ElectionException & ex)
	{

		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;

	}
	catch(VotingDeviceException & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(CryptoException & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(SignedException & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(XmlException & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(GuIdException & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(FileSystemException & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(std::exception & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(...)
	{
		std::cout << "FATAL "<<__func__<< "Unknown exception" << std::endl;
	}



	return loginOk;
}
Beispiel #16
0
// Send requests and collect statistics.
void sendRequests(){
  // Some variables...
  unsigned long completedRequests = 0;
  unsigned long failedRequests = 0;
  Glib::TimeVal completedTime(0,0);
  Glib::TimeVal failedTime(0,0);
  Glib::TimeVal tBefore;
  Glib::TimeVal tAfter;
  bool connected;

  //std::string url_str("https://127.0.0.1:60000/echo");
  Arc::URL url(url_str);

  Arc::MCCConfig mcc_cfg;
  Arc::UserConfig usercfg("");
  usercfg.ApplyToConfig(mcc_cfg);
  
  Arc::NS echo_ns; echo_ns["echo"]="http://www.nordugrid.org/schemas/echo";
  
  while(run){
    
    // Create a Client.
    Arc::ClientSOAP *client = NULL;
    client = new Arc::ClientSOAP(mcc_cfg,url,60);

    connected=true;
    while(run and connected){
      // Prepare the request.
      Arc::PayloadSOAP req(echo_ns);
      req.NewChild("echo:echo").NewChild("echo:say")="HELLO";

      // Send the request and time it.
      tBefore.assign_current_time();
      Arc::PayloadSOAP* resp = NULL;

      //std::string str;
      //req.GetXML(str);
      //std::cout<<"request: "<<str<<std::endl;
      Arc::MCC_Status status = client->process(&req,&resp);

      tAfter.assign_current_time();
      
      if(!status) {
        // Request failed.
        failedRequests++;
        failedTime+=tAfter-tBefore;
	    connected=false;
      } else {
        if(resp == NULL) {
          // Response was not SOAP or no response at all.
          failedRequests++;
          failedTime+=tAfter-tBefore;
          connected=false;
        } else {
          //std::string xml;
          //resp->GetXML(xml);
          if (std::string((*resp)["echoResponse"]["hear"]).size()==0){
            // The response was not what it should be.
            failedRequests++;
            failedTime+=tAfter-tBefore;
            connected=false;
          }
          else{
            // Everything worked just fine!
            completedRequests++;
            completedTime+=tAfter-tBefore;
          }
        }
      }
      if(resp) delete resp;
      if(alwaysReconnect) connected=false;
    }
    if(client) delete client;
  }

  // Update global variables.
  Glib::Mutex::Lock lock(*mutex);
  ::completedRequests+=completedRequests;
  ::failedRequests+=failedRequests;
  ::completedTime+=completedTime;
  ::failedTime+=failedTime;
  finishedThreads++;
  std::cout << "Number of finished threads: " << finishedThreads << std::endl;
}
Beispiel #17
0
bool CondTime::isInTheFuture() const
{
	Glib::TimeVal now;
	now.assign_current_time();
	return (now-timepoint).negative(); // timepoint > now
}