Exemple #1
0
bool load_configuration_values(const k3d::filesystem::path& file_path, k3d::double_t& recursion, k3d::double_t& basic_angle, k3d::double_t& thickness)
{
	// Open configuration file
	k3d::filesystem::ifstream file(file_path);
	if(!file.good())
	{
		k3d::log() << error << k3d_file_reference << ": error opening [" << file_path.native_console_string() << "]" << std::endl;
		return 0.0;
	}

	// Get recursion level
	std::string temp;
	return_val_if_fail(ls_line(file, temp), false);
	std::stringstream scan(temp);
	scan >> recursion;

	// Get asic angle
	return_val_if_fail(ls_line(file, temp), false);
	std::stringstream scan2(temp);
	scan2 >> basic_angle;

	// Get thickness
	return_val_if_fail(ls_line(file, temp), false);
	std::stringstream scan3(temp);
	scan3 >> thickness;

	return true;
}
template<typename ReaderT> void load_file(const k3d::filesystem::path& FilePath, const TCollection_ExtendedString& TypeName, implementation* Implementation)
{
	ReaderT reader; // create a CAF reader, which supports reading attributes like shape names, colors, ...
	reader.SetNameMode(true); // Make sure we read names
	IFSelect_ReturnStatus status = reader.ReadFile(const_cast<char*>(FilePath.native_filesystem_string().c_str())); // Read the file
	if(status != IFSelect_RetDone)
	{
		k3d::log() << error << k3d_file_reference << ": error opening [" << FilePath.native_console_string() << "]" << std::endl;
		throw std::exception();
	}

	Implementation->xde_doc = new TDocStd_Document(TypeName); // initialise an empty document
	if (!reader.Transfer(Implementation->xde_doc)) // attempt to transfer the STEP file contents to the document
	{
		k3d::log() << error << "Failed to transfer OpenCascade file" << std::endl;
		throw std::exception();
	}

	if(!XCAFDoc_DocumentTool::IsXCAFDocument(Implementation->xde_doc)) // sanity check
	{
		k3d::log() << error << "Invalid document" << std::endl;
		throw std::exception();
	}

	TDF_Label shaperoot = XCAFDoc_DocumentTool::ShapesLabel(Implementation->xde_doc->Main()); // get the root node for the geometric shapes
	Implementation->shapes.push(TDF_ChildIterator(shaperoot));
}
Exemple #3
0
	const k3d::bool_t test_type(const k3d::string_t& TestExtension, const k3d::string_t& TestType, const k3d::filesystem::path& File, k3d::string_t& FileType)
	{
		if(TestExtension != k3d::filesystem::extension(File).lowercase().raw())
			return false;

		FileType = TestType;

		k3d::log() << info << "Identified " << File.native_console_string() << " as " << FileType << " using " << get_factory().name() << std::endl;
		return true;
	}
Exemple #4
0
	bool read_file(const k3d::filesystem::path& Path, k3d::bitmap& Bitmap)
	{
		try
		{
			k3d::log() << info << "Reading " << Path.native_console_string() << " using " << get_factory().name() << std::endl;
			boost::gil::read_and_convert_image(Path.native_filesystem_string(), Bitmap, boost::gil::jpeg_tag());
			return true;
		}
		catch(std::exception& e)
		{
			k3d::log() << error << k3d_file_reference << ": caught exception: " << e.what() << std::endl;
			return false;
		}
		catch(...)
		{
			k3d::log() << error << k3d_file_reference << ": caught unknown exception" << std::endl;
			return false;
		}
	}
Exemple #5
0
Glib::RefPtr<Gdk::Pixbuf> load_pixbuf(const k3d::filesystem::path& SharePath, const k3d::filesystem::path& Path)
{
	Glib::RefPtr<Gdk::Pixbuf> result;
	const k3d::filesystem::path path = SharePath / Path;
	try
	{
		result = Gdk::Pixbuf::create_from_file(path.native_filesystem_string());
	}
	catch(Glib::Exception& e)
	{
		k3d::log() << error << e.what() << std::endl;
	}
	catch(std::exception& e)
	{
		k3d::log() << error << e.what() << std::endl;
	}
	catch(...)
	{
		k3d::log() << error << "Unknown exception loading [" << path.native_console_string() << "]" << std::endl;
	}

	return result;
}
Exemple #6
0
/// Creates plugin factories at runtime based on the contents of a directory
void register_plugins(const k3d::filesystem::path& Path, k3d::iplugin_registry& Registry)
{
	k3d::log() << info << "Loading scripts from " << Path.native_console_string() << std::endl;

	boost::regex metadata_expression("((k3d|ngui|qtui):[^=]*)=\"([^\"]*)\"");

	// There are very few SDK functions that can be safely called at this point in execution, but k3d::share_path() happens to be one of them ...
	for(k3d::filesystem::directory_iterator script_path(Path); script_path != k3d::filesystem::directory_iterator(); ++script_path)
	{
		if(k3d::filesystem::is_directory(*script_path))
			continue;

		k3d::filesystem::ifstream script_file(*script_path);
		std::stringstream script_stream;
		script_stream << script_file.rdbuf();
		k3d::string_t script = script_stream.str();

		k3d::string_t plugin_class;
		k3d::string_t plugin_type;
		k3d::string_t plugin_name;
		k3d::string_t plugin_description = _("Scripted Plugin.");
		k3d::iplugin_factory::metadata_t plugin_metadata;

		for(boost::sregex_iterator metadata(script.begin(), script.end(), metadata_expression); metadata != boost::sregex_iterator(); ++metadata)
		{
			const k3d::string_t name = (*metadata)[1].str();
			const k3d::string_t value = (*metadata)[3].str();

			if(name == "k3d:plugin-class")
				plugin_class = value;
			else if(name == "k3d:plugin-type")
			{
				plugin_type = value;
				plugin_metadata.insert(std::make_pair(name, value));
			}
			else if(name == "k3d:plugin-name")
				plugin_name = value;
			else if(name == "k3d:plugin-description")
				plugin_description = value;
			else
				plugin_metadata.insert(std::make_pair(name, value));
		}

		// Automatically disable documentation for all scripted plugins ...
		plugin_metadata.insert(std::make_pair("k3d:disable-documentation", ""));

		if(plugin_class.empty())
		{
			continue;
		}

		if(plugin_class != "application" && plugin_class != "document")
		{
			k3d::log() << error << "Script [" << script_path->native_console_string() << "] using unknown plugin class [" << plugin_class << "] will not be loaded" << std::endl;
			continue;
		}

		if(plugin_type.empty())
		{
			k3d::log() << error << "Script [" << script_path->native_console_string() << "] without k3d:plugin-type property will not be loaded" << std::endl;
			continue;
		}

		if(plugin_name.empty())
		{
			k3d::log() << error << "Script [" << script_path->native_console_string() << "] without k3d:plugin-name property will not be loaded" << std::endl;
			continue;
		}

		if(plugin_class == "application")
		{
			k3d::iplugin_factory* const factory = new application_factory(
				*script_path,
				plugin_type,
				k3d::uuid::random(),
				plugin_name,
				plugin_description,
				"Scripts",
				k3d::iplugin_factory::STABLE,
				plugin_metadata);

			Registry.register_factory(*factory);
		}
		else if(plugin_class == "document")
		{
			k3d::iplugin_factory* const factory = new document_factory(
				*script_path,
				plugin_type,
				k3d::uuid::random(),
				plugin_name,
				plugin_description,
				"Scripts",
				k3d::iplugin_factory::STABLE,
				plugin_metadata);

			Registry.register_factory(*factory);
		}
	}
}
Exemple #7
0
// Process a ls file and setup rules
bool load_configuration_rules(const k3d::double_t recursion, const k3d::double_t basic_angle, const k3d::double_t thickness, const k3d::filesystem::path& file_path)
{
	// Open grammar file
	k3d::filesystem::ifstream file(file_path);
	if(!file.good())
	{
		k3d::log() << error << k3d_file_reference << ": error opening [" << file_path.native_console_string() << "]" << std::endl;
		return false;
	}

	// Set default values
	trope_set = false;
	rand_set = false;
	closed_form = false;
	last_recur = false;

	min_thick = 0.0; rand_amount = 0.0;
	trope_amount = 0.0;
	polcount = 0;
	poly_limit = 500000L;
	col = 2; last_col = 0;
	tr = 0.2;
	sky = k3d::vector3(0.0, 0.0, 1.0);
	last = k3d::point3(1.0, 1.0, 1.0);

	// Clear stacks
	stack = std::stack<s_rec>();
	pstack = std::stack<vectors_t>();

	// Skip but setup recursion level, basic angle and thickness
	std::string temp;
	return_val_if_fail(ls_line(file, temp), false);

	lev = (unsigned long)std::floor(recursion);
	fraction = recursion - (k3d::double_t)lev;
	if(fraction > 0)
		lev++;

	return_val_if_fail(ls_line(file, temp), false);
	ang = basic_angle / 180 * 3.141592654;

	return_val_if_fail(ls_line(file, temp), false);
	thick = thickness / 100;

	// Axiom
	return_val_if_fail(ls_line(file, temp), false);

	object_string = strtok(const_cast<char*>(temp.c_str()), " \r\n\t#");

	// Get rules
	rules.clear();
	for(unsigned long i = 0; i < 150; i++)
	{
		return_val_if_fail(ls_line(file, temp), false);

		std::string rule = strtok(const_cast<char*>(temp.c_str()), " \r\n\t#");

		if(!rule.size())
			continue;

		if(rule[0] == '@')
			break;

		rules.push_back(rule);
	}

	// Add default rules
	rules.push_back("+=+");
	rules.push_back("-=-");
	rules.push_back("&=&");
	rules.push_back("^=^");
	rules.push_back("<=<");
	rules.push_back(">=>");

	rules.push_back("%=%");
	rules.push_back("|=|");
	rules.push_back("!=!");
	rules.push_back("?=?");
	rules.push_back(":=:");
	rules.push_back(";=;");
	rules.push_back("\'=\'");
	rules.push_back("\"=\"");
	rules.push_back("c=c");

	rules.push_back("[=[");
	rules.push_back("]=]");
	rules.push_back("{={");
	rules.push_back("}=}");

	rules.push_back("F=F");
	rules.push_back("f=f");
	rules.push_back("t=t");
	rules.push_back("g=g");
	rules.push_back("Z=Z");
	rules.push_back("z=z");
	rules.push_back("*=*");
	rules.push_back("$=$");
	rules.push_back("~=~");

	rules.push_back(".=.");
	rules.push_back("1=1");
	rules.push_back("2=2");
	rules.push_back("3=3");
	rules.push_back("4=4");
	rules.push_back("5=5");
	rules.push_back("6=6");
	rules.push_back("7=7");
	rules.push_back("8=8");
	rules.push_back("9=9");
	rules.push_back("0=0");
	rules.push_back("(=(");
	rules.push_back(")=)");

	// Closer default
	rules.push_back("_=_");

	// Set start values for F and Z distances
	dis = 100.0;
	dis2 = dis * 0.5;

	// Get marks
	marks.clear();
	for(unsigned long n = 0; n < rules.size(); n++)
		marks.push_back(false);

	// Check which rules need to be marked for last recursion when growing
	for(unsigned long n = 0; n < rules.size(); n++)
	{
		if(rules[n][0] == '+')
			break;

		marks[n] = true;

		// All rules with basic move/block before '=' mark false
		if(rules[n][0] == 'F')
			marks[n] = false;
		if(rules[n][0] == 'f')
			marks[n] = false;
		if(rules[n][0] == 'Z')
			marks[n] = false;
		if(rules[n][0] == 'z')
			marks[n] = false;
	}

	return true;
}