Пример #1
0
void
FilterFactoryBase::attach_imengine_factory (const IMEngineFactoryPointer &orig)
{
    m_orig = orig;

    if (!m_orig.null ())
        set_locales (m_orig->get_locales ());
    else
        set_locales ("");
}
Пример #2
0
void File::loadTriangles(vector< vector<Triangle> > &triangles,
			 vector<ustring> &names,
			 uint max_triangles)
{
  Gio::FileType type = _file->query_file_type();
  if (type != Gio::FILE_TYPE_REGULAR &&
      type != Gio::FILE_TYPE_SYMBOLIC_LINK)
    return;

  ustring name_by_file = _file->get_basename();
  size_t found = name_by_file.find_last_of(".");
  name_by_file = (ustring)name_by_file.substr(0,found);

  set_locales("C");
  if(_type == ASCII_STL) {
    // multiple shapes per file
    load_asciiSTL(triangles, names, max_triangles);
    if (names.size() == 1) // if single shape name by file
      names[0] = name_by_file;
    if (triangles.size() == 0) {// if no success, try binary mode
      _type = BINARY_STL;
      loadTriangles(triangles, names, max_triangles);
      return;
    }
  } else if (_type == AMF) {
    // multiple shapes per file
    load_AMF(triangles, names, max_triangles);
    if (names.size() == 1) // if single shape name by file
      names[0] = name_by_file;
  } else {
    // single shape per file
    triangles.resize(1);
    names.resize(1);
    names[0] = name_by_file;
    if (_type == BINARY_STL) {
      load_binarySTL(triangles[0], max_triangles);
    } else if (_type == VRML) {
      load_VRML(triangles[0], max_triangles);
    } else {
      cerr << _("Unrecognized file - ") << _file->get_parse_name() << endl;
      cerr << _("Known extensions: ") << "STL, WRL, AMF." << endl;
    }
  }
  reset_locales();
}
Пример #3
0
void GCode::Read(Model *model, const vector<char> E_letters,
		 ViewProgress *progress, string filename)
{
	clear();

	ifstream file;
	file.open(filename.c_str());		//open a file
	file.seekg (0, ios::end);
	double filesize = double(file.tellg());
	file.seekg (0);

	progress->start(_("Loading GCode"), filesize);
	int progress_steps=(int)(filesize/1000);
	if (progress_steps==0) progress_steps=1;

	buffer_zpos_lines.clear();

	if(!file.good())
	{
//		MessageBrowser->add(str(boost::format("Error opening file %s") % Filename).c_str());
		return;
	}

	set_locales("C");

	uint LineNr = 0;

	string s;

	bool relativePos = false;
	Vector3d globalPos(0,0,0);
	Min.set(99999999.0,99999999.0,99999999.0);
	Max.set(-99999999.0,-99999999.0,-99999999.0);

	std::vector<Command> loaded_commands;

	double lastZ=0.;
	double lastE=0.;
	double lastF=0.;
	layerchanges.clear();

	stringstream alltext;

	int current_extruder = 0;

	while(getline(file,s))
	{
	  alltext << s << endl;

		LineNr++;
		unsigned long fpos = file.tellg();
		if (fpos%progress_steps==0) if (!progress->update(fpos)) break;

		Command command;

		if (relativePos)
		  command = Command(s, Vector3d::ZERO, E_letters);
		else
		  command = Command(s, globalPos, E_letters);

		if (command.Code == COMMENT) {
		  continue;
		}
		if (command.Code == UNKNOWN) {
		  cerr << "Unknown GCode " << s << endl;
		  continue;
		}
		if (command.Code == RELATIVEPOSITIONING) {
		  relativePos = true;
		  continue;
		}
		if (command.Code == ABSOLUTEPOSITIONING) {
		  relativePos = false;
		  continue;
		}
		if (command.Code == SELECTEXTRUDER) {
		  current_extruder = command.extruder_no;
		  continue;
		}
		command.extruder_no = current_extruder;

		// not used yet
		// if (command.Code == ABSOLUTE_ECODE) {
		//   relativeE = false;
		//   continue;
		// }
		// if (command.Code == RELATIVE_ECODE) {
		//   relativeE = true;
		//   continue;
		// }

		if (command.e == 0)
		  command.e  = lastE;
		else
		  lastE = command.e;

		if (command.f != 0)
		  lastF = command.f;
		else
		  command.f = lastF;

		// cout << s << endl;
		//cerr << command.info()<< endl;
		// if(command.where.x() < -100)
		//   continue;
		// if(command.where.y() < -100)
		//   continue;

		if (command.Code == SETCURRENTPOS) {
		  continue;//if (relativePos) globalPos = command.where;
		}
		else {
		  command.addToPosition(globalPos, relativePos);
		}

		if (globalPos.z() < 0){
		  cerr << "GCode below zero!"<< endl;
		  continue;
		}

		if ( command.Code == RAPIDMOTION ||
		     command.Code == COORDINATEDMOTION ||
		     command.Code == ARC_CW ||
		     command.Code == ARC_CCW ||
		     command.Code == GOHOME ) {

		  if(globalPos.x() < Min.x())
		    Min.x() = globalPos.x();
		  if(globalPos.y() < Min.y())
		    Min.y() = globalPos.y();
		  if(globalPos.z() < Min.z())
		    Min.z() = globalPos.z();
		  if(globalPos.x() > Max.x())
		    Max.x() = globalPos.x();
		  if(globalPos.y() > Max.y())
		    Max.y() = globalPos.y();
		  if(globalPos.z() > Max.z())
		    Max.z() = globalPos.z();
		  if (globalPos.z() > lastZ) {
		    // if (lastZ > 0){ // don't record first layer
		    unsigned long num = loaded_commands.size();
		    layerchanges.push_back(num);
		    loaded_commands.push_back(Command(LAYERCHANGE, layerchanges.size()));
		    // }
		    lastZ = globalPos.z();
		    buffer_zpos_lines.push_back(LineNr-1);
		  }
		  else if (globalPos.z() < lastZ) {
		    lastZ = globalPos.z();
		    if (layerchanges.size()>0)
		      layerchanges.erase(layerchanges.end()-1);
		  }
		}
		loaded_commands.push_back(command);
	}

	file.close();
	reset_locales();

	commands = loaded_commands;

	buffer->set_text(alltext.str());

	Center = (Max + Min)/2;

	model->m_signal_gcode_changed.emit();

	double time = GetTimeEstimation();
	int h = (int)time/3600;
	int min = ((int)time%3600)/60;
	int sec = ((int)time-3600*h-60*min);
	cerr << "GCode Time Estimation "<< h <<"h "<<min <<"m " <<sec <<"s" <<endl;
	//??? to statusbar or where else?
}
Пример #4
0
SocketFactory::SocketFactory (const String &peer_uuid)
    : m_name (utf8_mbstowcs (_("Unknown"))),
      m_language (String ("")),
      m_peer_uuid (peer_uuid),
      m_icon_file (String ("")),
      m_ok (false)
{
    String locales;
    String iconfile;
    int cmd;
    bool m_name_ok = false;
    bool m_locale_ok = false;
    Transaction trans;

    SCIM_DEBUG_IMENGINE(1) << "Create SocketFactory " << peer_uuid << ".\n";

    // Get factory name.
    global->init_transaction (trans);
    trans.put_command (SCIM_TRANS_CMD_GET_FACTORY_NAME);
    trans.put_data (m_peer_uuid);
    if (global->send_transaction (trans)) {
        if (global->receive_transaction (trans) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
            trans.get_data (m_name) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) {

            SCIM_DEBUG_IMENGINE(2) << " Name (" << utf8_wcstombs (m_name) << ")\n";

            m_name_ok = true;

        } else {
            m_name = utf8_mbstowcs (_("Unknown"));
        }
    }

    // Get factory locales
    global->init_transaction (trans);
    trans.put_command (SCIM_TRANS_CMD_GET_FACTORY_LOCALES);
    trans.put_data (m_peer_uuid);
    if (global->send_transaction (trans)) {
        if (global->receive_transaction (trans) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
            trans.get_data (locales) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) {

            SCIM_DEBUG_IMENGINE(2) << " Locales (" << locales << ")\n";

            set_locales (locales);
            m_locale_ok = true;
        }
    }

    // Get factory language
    global->init_transaction (trans);
    trans.put_command (SCIM_TRANS_CMD_GET_FACTORY_LANGUAGE);
    trans.put_data (m_peer_uuid);
    if (global->send_transaction (trans)) {
        if (global->receive_transaction (trans) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
            trans.get_data (m_language) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) {

            SCIM_DEBUG_IMENGINE(2) << " Language (" << m_language << ")\n";

        } else {
            m_language.clear ();
        }
    }

    // Get icon file.
    global->init_transaction (trans);
    trans.put_command (SCIM_TRANS_CMD_GET_FACTORY_ICON_FILE);
    trans.put_data (m_peer_uuid);
    if (global->send_transaction (trans)) {
        if (global->receive_transaction (trans) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
            trans.get_data (iconfile) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) {
            m_icon_file = global->load_icon (iconfile);
        }
    }

    m_ok = (m_name_ok && m_locale_ok);
}
Пример #5
0
ComposeKeyFactory::ComposeKeyFactory ()
{
    set_locales ("C");
}