Example #1
0
	void set_parent(viewport::control& Viewport, k3d::inode& Parent)
	{
		m_set_parent = false;
		m_document_state.clear_cursor_signal().emit();

		k3d::imatrix_source* const matrix_source = dynamic_cast<k3d::imatrix_source*>(&Parent);
		return_if_fail(matrix_source);

		const k3d::matrix4 parent_compensation = k3d::inverse(k3d::node_to_world_matrix(Parent));

		k3d::ipipeline::dependencies_t dependencies;

		k3d::record_state_change_set changeset(m_document_state.document(), _("Set Parent"), K3D_CHANGE_SET_CONTEXT);

		// Note - we enumerate over a *copy* of the set of document nodes, since we're adding nodes as we go ...
		const k3d::nodes_t nodes = m_document_state.document().nodes().collection();
		for(k3d::nodes_t::const_iterator node = nodes.begin(); node != nodes.end(); ++node)
		{
			// Ensure we don't try to parent an object to itself ...
			if(&Parent == *node)
				continue;

			if(!selection::state(m_document_state.document()).is_selected(**node))
				continue;

			const transform_history_t history = parent_to_node_history(**node);
			if(!history.empty())
			{
				if(k3d::imatrix_sink* const matrix_sink = dynamic_cast<k3d::imatrix_sink*>(history.front()))
				{
					const transform_modifier modifier = create_transform_modifier(m_document_state.document(), k3d::classes::FrozenMatrix(), "Parent Compensation");
					if(modifier)
					{
						k3d::property::set_internal_value(*modifier.node, "matrix", parent_compensation);
						dependencies.insert(std::make_pair(&matrix_sink->matrix_sink_input(), &modifier.source->matrix_source_output()));
						dependencies.insert(std::make_pair(&modifier.sink->matrix_sink_input(), &matrix_source->matrix_source_output()));
					}
				}
			}

			if(k3d::iparentable* const parentable = dynamic_cast<k3d::iparentable*>(*node))
			{
				if(k3d::iwritable_property* const writable_parent = dynamic_cast<k3d::iwritable_property*>(&parentable->parent()))
					writable_parent->property_set_value(&Parent);
			}
		}

		selection::state(m_document_state.document()).deselect_all();
		selection::state(m_document_state.document()).select(Parent);
		m_document_state.document().pipeline().set_dependencies(dependencies);
	}
Example #2
0
 Area& operator=(const Area& area) {
     id(area.id());
     version(area.version());
     changeset(area.changeset());
     timestamp(area.timestamp());
     endtime(area.endtime());
     uid(area.uid());
     user(area.user());
     visible(area.visible());
     tags(area.tags());
     m_node_list = area.m_node_list;
     m_relation_member_list = area.m_relation_member_list;
     m_geos_geometry = dynamic_cast<geos::geom::MultiPolygon*>(area.m_geos_geometry->clone());
     return *this;
 }
bool
RealTrafficIPC::sendChangeset( const Disturbances& newElements,
                               const Disturbances& removedElements ) {
   Disturbances newClonedElements;
   Disturbances removedClonedElements;
   clone( newElements, newClonedElements );
   clone( removedElements, removedClonedElements );

   DisturbanceChangeset changeset( newClonedElements, removedClonedElements );
   // create the packet
   DisturbanceChangesetRequestPacket* packet = 
      new DisturbanceChangesetRequestPacket( Packet::PacketID( 0 ),
                                             m_moduleCom.getNextRequestID(),
                                             changeset );
   uint32 mapID = MAX_UINT32;
   if ( ! newElements.empty() ) {
      mapID = newElements.front()->getMapID();
   } else if ( ! removedElements.empty() ) {
      mapID = removedElements.front()->getMapID();
   }

   packet->setMapID( mapID );
   // send the packet and get the packet container as a return.
   auto_ptr<PacketContainer> cont( m_moduleCom.
                                   putRequest( packet, MODULE_TYPE_TRAFFIC ) );

   DisturbanceChangesetReplyPacket* answer;
   if ( getValidPacket( answer, cont.get() ) ) {
      if( answer && answer->getStatus() == StringTable::OK ) {
         mc2dbg4 << "[RTIPC] send change set OK" << endl;
         return true;
      } else {

         if ( answer->getUpdateStatus() == StringTable::NOTOK ) {
            mc2log << warn
                   << "[RTIPC] Failed to update new DisturbanceElements."
                   << endl;
         } 

         if ( answer->getRemoveStatus() == StringTable::NOTOK ) {
            mc2log << warn
                   << "[RTIPC] Failed to remove old DisturbanceElements."
                   << endl;
         }
      }
   }
   return false;
}
Example #4
0
void
flushchanges(void)
{
	int a, b, c, d, at;
	int i, j;

	if(nchanges == 0)
		return;
	
	for(i=0; i<nchanges; ){
		j = changeset(i);
		a = changes[i].a-Lines;
		b = changes[j-1].b+Lines;
		c = changes[i].c-Lines;
		d = changes[j-1].d+Lines;
		if(a < 1)
			a = 1;
		if(c < 1)
			c = 1;
		if(b > len[0])
			b = len[0];
		if(d > len[1])
			d = len[1];
		if(mode == 'a'){
			a = 1;
			b = len[0];
			c = 1;
			d = len[1];
			j = nchanges;
		}
		Bprint(&stdout, "%s:", file1);
		range(a, b, ",");
		Bprint(&stdout, " - ");
		Bprint(&stdout, "%s:", file2);
		range(c, d, ",");
		Bputc(&stdout, '\n');
		at = a;
		for(; i<j; i++){
			fetch(ixold, at, changes[i].a-1, input[0], "  ");
			fetch(ixold, changes[i].a, changes[i].b, input[0], "- ");
			fetch(ixnew, changes[i].c, changes[i].d, input[1], "+ ");
			at = changes[i].b+1;
		}
		fetch(ixold, at, b, input[0], "  ");
	}
	nchanges = 0;
}
Example #5
0
 /**
  * Set named attribute.
  * @param attr Name of the attribute (must be one of "id", "version", "changeset", "timestamp", "uid", "user", "visible")
  * @param value Value of the attribute
  */
 void set_attribute(const char* attr, const char* value) {
     if (!strcmp(attr, "id")) {
         id(value);
     } else if (!strcmp(attr, "version")) {
         version(value);
     } else if (!strcmp(attr, "changeset")) {
         changeset(value);
     } else if (!strcmp(attr, "timestamp")) {
         timestamp(value);
     } else if (!strcmp(attr, "uid")) {
         uid(value);
     } else if (!strcmp(attr, "user")) {
         user(value);
     } else if (!strcmp(attr, "visible")) {
         visible(value);
     }
 }
Example #6
0
/// Modify transformation
inode* modify_transformation(idocument& Document, inode& Object, iplugin_factory* Modifier)
{
	return_val_if_fail(Modifier, 0);

	// Get the upstream and downstream properties ...
	imatrix_sink* const downstream_sink = dynamic_cast<imatrix_sink*>(&Object);
	return_val_if_fail(downstream_sink, 0);

	iproperty& downstream_input = downstream_sink->matrix_sink_input();

	iproperty* const upstream_output = Document.pipeline().dependency(downstream_input);

	inode* modifier = 0;

	// This block is recorded for undo purposes ...
	{
		record_state_change_set changeset(Document, string_cast(boost::format(_("Add Modifier %1%")) % Modifier->name()), K3D_CHANGE_SET_CONTEXT);

		// Create our modifier object ...
		modifier = plugin::create<inode>(*Modifier, Document, unique_name(Document.nodes(), Modifier->name()));
		return_val_if_fail(modifier, 0);

		// Get its input and output properties ...
		imatrix_sink* const modifier_sink = dynamic_cast<imatrix_sink*>(modifier);
		return_val_if_fail(modifier_sink, 0);
		imatrix_source* const modifier_source = dynamic_cast<imatrix_source*>(modifier);
		return_val_if_fail(modifier_source, 0);

		// Insert the modifier into the DAG ...
		ipipeline::dependencies_t dependencies;
		if(upstream_output)
			dependencies.insert(std::make_pair(&modifier_sink->matrix_sink_input(), upstream_output));
		dependencies.insert(std::make_pair(&downstream_input, &modifier_source->matrix_source_output()));
		Document.pipeline().set_dependencies(dependencies);
	}

	return modifier;
}
Example #7
0
 v8::Handle<v8::Value> js_changeset() const {
     return v8::Number::New(changeset());
 }
Example #8
0
void modify_selected_meshes(document_state& DocumentState, iplugin_factory* Modifier)
{
	return_if_fail(Modifier);
	idocument& document = DocumentState.document();
	if (Modifier->implements(typeid(imulti_mesh_sink)))
	{ // Mesh modifier taking multiple inputs
		uint_t count = 0;
		ipipeline::dependencies_t dependencies;
		const nodes_t selected_nodes = selection::state(DocumentState.document()).selected_nodes();
		// Create the node
		inode* multi_sink = pipeline::create_node(document, *Modifier);
		record_state_change_set changeset(document, string_cast(boost::format(_("Add Modifier %1%")) % Modifier->name()), K3D_CHANGE_SET_CONTEXT);
		nodes_t nodes_to_delete;
		for(nodes_t::const_iterator node = selected_nodes.begin(); node != selected_nodes.end(); ++node)
		{
			imesh_sink* const mesh_sink = dynamic_cast<imesh_sink*>(*node);
			if(!mesh_sink)
				continue;
			imatrix_sink* const matrix_sink = dynamic_cast<imatrix_sink*>(*node);

			iproperty* source_mesh = document.pipeline().dependency(mesh_sink->mesh_sink_input());
			if (!source_mesh)
				continue;
			
			if (matrix_sink) // Insert a transform node
			{
				iproperty* const source_transformation = document.pipeline().dependency(matrix_sink->matrix_sink_input());
				if (source_transformation)
				{
					inode* transform_points = plugin::create<inode>("TransformPoints", document, unique_name(document.nodes(), "TransformPoints"));
					return_if_fail(transform_points);
					imatrix_sink* transform_points_matrix_sink = dynamic_cast<imatrix_sink*>(transform_points);
					return_if_fail(transform_points_matrix_sink);
					imesh_sink* transform_points_mesh_sink = dynamic_cast<imesh_sink*>(transform_points);
					return_if_fail(transform_points_mesh_sink);
					dependencies.insert(std::make_pair(&transform_points_matrix_sink->matrix_sink_input(), source_transformation));
					dependencies.insert(std::make_pair(&transform_points_mesh_sink->mesh_sink_input(), source_mesh));
					imesh_source* transform_points_mesh_source = dynamic_cast<imesh_source*>(transform_points);
					return_if_fail(transform_points_mesh_source);
					source_mesh = &transform_points_mesh_source->mesh_source_output();
					imesh_selection_sink* selection_sink = dynamic_cast<imesh_selection_sink*>(transform_points);
					return_if_fail(selection_sink);
					property::set_internal_value(selection_sink->mesh_selection_sink_input(), k3d::geometry::selection::create(1.0));
				}
			}
			++count;
			// Create a new user property
			std::stringstream name, label;
			name << "input_mesh" << count;
			label << "Input Mesh " << count;
			iproperty* sink = property::get(*multi_sink, name.str());
			if (!sink)
				sink = property::create<mesh*>(*multi_sink, name.str(), label.str(), "", static_cast<mesh*>(0));
			// Store the connection
			dependencies.insert(std::make_pair(sink, source_mesh));
			// Delete the input node
			nodes_to_delete.push_back(*node);
		}
		document.pipeline().set_dependencies(dependencies);
		delete_nodes(document, nodes_to_delete);
		// Give nodes a chance to initialize their property values based on their inputs, if any ...
		if(ireset_properties* const reset_properties = dynamic_cast<ireset_properties*>(multi_sink))
			reset_properties->reset_properties();

		panel::mediator(DocumentState.document()).set_focus(*multi_sink);
	}
	else
	{ // Normal mesh modifier
		nodes_t new_modifiers;
	
		const nodes_t selected_nodes = selection::state(DocumentState.document()).selected_nodes();
		for(nodes_t::const_iterator node = selected_nodes.begin(); node != selected_nodes.end(); ++node)
		{
			new_modifiers.push_back(modify_mesh(DocumentState, **node, Modifier));
			assert_warning(new_modifiers.back());
		}
	
		// Show the new modifier properties if only one was processed
		if(selected_nodes.size() == 1)
		{
			panel::mediator(DocumentState.document()).set_focus(*new_modifiers.front());
		}
		else // otherwise connect all parameter properties to the first node and show that one
		{
			iproperty_collection* first_property_collection = dynamic_cast<iproperty_collection*>(new_modifiers.front());
			if (first_property_collection)
			{
				// Get the in-and output property names, to exclude them from the connections
				imesh_sink* const modifier_sink = dynamic_cast<imesh_sink*>(new_modifiers.front());
				return_if_fail(modifier_sink);
				imesh_source* const modifier_source = dynamic_cast<imesh_source*>(new_modifiers.front());
				return_if_fail(modifier_source);
				const std::string sink_name = modifier_sink->mesh_sink_input().property_name();
				const std::string source_name = modifier_source->mesh_source_output().property_name();
				
				ipipeline::dependencies_t dependencies;
				const iproperty_collection::properties_t& first_properties = first_property_collection->properties();
				nodes_t::iterator modifier = new_modifiers.begin();
				++modifier;
				for (modifier; modifier != new_modifiers.end(); ++modifier)
				{
					iproperty_collection* property_collection = dynamic_cast<iproperty_collection*>(*modifier);
					return_if_fail(property_collection);
					const iproperty_collection::properties_t& properties = property_collection->properties();
					iproperty_collection::properties_t::const_iterator property = properties.begin();
					for (iproperty_collection::properties_t::const_iterator first_property = first_properties.begin(); first_property != first_properties.end(); ++first_property)
					{
						return_if_fail(property != properties.end());
						return_if_fail((*property)->property_name() == (*first_property)->property_name());
						if ((*property)->property_name() == sink_name || (*property)->property_name() == source_name || (*property)->property_name() == "name")
						{
							++property;
							continue;
						}
						dependencies.insert(std::make_pair(*property, *first_property));
						++property;
					}
				}
				document.pipeline().set_dependencies(dependencies);
				panel::mediator(DocumentState.document()).set_focus(*new_modifiers.front());
			}
		}
	}
}
Example #9
0
/// Modify mesh
inode* modify_mesh(document_state& DocumentState, inode& Node, iplugin_factory* Modifier)
{
	return_val_if_fail(Modifier, 0);

	idocument& document = DocumentState.document();
	
	// Get the upstream and downstream properties ...
	imesh_sink* const downstream_sink = dynamic_cast<imesh_sink*>(&Node);
	return_val_if_fail(downstream_sink, 0);

	iproperty& downstream_input = downstream_sink->mesh_sink_input();

	iproperty* const upstream_output = document.pipeline().dependency(downstream_input);
	return_val_if_fail(upstream_output, 0);

	inode* modifier = 0;

	// This block is recorded for undo purposes ...
	{
		record_state_change_set changeset(document, string_cast(boost::format(_("Add Modifier %1%")) % Modifier->name()), K3D_CHANGE_SET_CONTEXT);

		// Create our modifier object ...
		modifier = plugin::create<inode>(*Modifier, document, unique_name(document.nodes(), Modifier->name()));
		return_val_if_fail(modifier, 0);

		// Get its input and output properties ...
		imesh_sink* const modifier_sink = dynamic_cast<imesh_sink*>(modifier);
		return_val_if_fail(modifier_sink, 0);
		imesh_source* const modifier_source = dynamic_cast<imesh_source*>(modifier);

		// Insert the modifier into the pipeline ...
		ipipeline::dependencies_t dependencies;
		dependencies.insert(std::make_pair(&modifier_sink->mesh_sink_input(), upstream_output));
		if(modifier_source)
			dependencies.insert(std::make_pair(&downstream_input, &modifier_source->mesh_source_output()));
		document.pipeline().set_dependencies(dependencies);

		// If the modifier is a mesh selection sink, set its selection state ...
		imesh_selection_sink* const modifier_mesh_selection_sink = dynamic_cast<imesh_selection_sink*>(modifier);
		imesh_selection_sink* const downstream_mesh_selection_sink = dynamic_cast<imesh_selection_sink*>(&Node);
		if(modifier_mesh_selection_sink && downstream_mesh_selection_sink)
		{
			if(selection::NODE == selection::state(DocumentState.document()).current_mode())
			{
				property::set_internal_value(
					modifier_mesh_selection_sink->mesh_selection_sink_input(),
					geometry::selection::create(1));
			}
			else
			{
				property::set_internal_value(
					modifier_mesh_selection_sink->mesh_selection_sink_input(),
					downstream_mesh_selection_sink->mesh_selection_sink_input().property_internal_value());
			}
	
			property::set_internal_value(
				downstream_mesh_selection_sink->mesh_selection_sink_input(),
				k3d::selection::set());
		}
	}
	
	// Give nodes a chance to initialize their property values based on their inputs, if any ...
	if(ireset_properties* const reset_properties = dynamic_cast<ireset_properties*>(modifier))
		reset_properties->reset_properties();

	return modifier;
}