Beispiel #1
0
bool isFirstMax(ListElement *first, ListElement *second, bool valueIsTelephone)
{
	if (valueIsTelephone)
		return telephoneListElement(first) > telephoneListElement(second);
	char *name1 = nameElement(first);
	char *name2 = nameElement(second);
	return (strcmp(name1, name2) > 0);
}
void SvgSerializer::finalize() {

	if (rescale) {
		// Scale the resulting image to a bounding rectangle specified by command line arguments
		const double dx = xmax - xmin;
		const double dy = ymax - ymin;

		double sc = 1.;

		if (dx / width > dy / height) {
			sc = width / dx;
		} else {
			sc = height / dy;
		}

		const double cx = xmin * sc;
		const double cy = ymin * sc;

		{std::vector< SHARED_PTR<util::string_buffer::float_item> >::const_iterator it;
		for (it = xcoords.begin(); it != xcoords.end(); ++it) {
			double& v = (*it)->value();
			v = v * sc - cx;
		}
		for (it = ycoords.begin(); it != ycoords.end(); ++it) {
			double& v = (*it)->value();
			v = v * sc - cy;
		}
		for (it = radii.begin(); it != radii.end(); ++it) {
			(*it)->value() *= sc;
		}}
	}

	std::multimap<IfcSchema::IfcBuildingStorey*, path_object>::const_iterator it;

	IfcSchema::IfcBuildingStorey* previous = 0;
	bool first = true;
	for (it = paths.begin(); it != paths.end(); ++it) {
		if (it->first != previous || first) {
			if (!first) {
				svg_file << "    </g>\n";
			}
			std::ostringstream oss;
			svg_file << "    <g " << nameElement(it->first) << ">\n";
		}
		svg_file << "        <g " << it->second.first << ">\n";
		std::vector<util::string_buffer>::const_iterator jt;
		for (jt = it->second.second.begin(); jt != it->second.second.end(); ++jt) {
			svg_file << jt->str();
		}
		svg_file << "        </g>\n";
		previous = it->first;
		first = false;
	}
	
	svg_file << "    </g>\n";
	svg_file << "</svg>" << std::endl;
}
Beispiel #3
0
std::string VCardSerializer::serializePayload(boost::shared_ptr<VCard> vcard)  const {
	XMLElement queryElement("vCard", "vcard-temp");
	if (!vcard->getVersion().empty()) {
		queryElement.addNode(boost::make_shared<XMLElement>("VERSION", "", vcard->getVersion()));
	}
	if (!vcard->getFullName().empty()) {
		queryElement.addNode(boost::make_shared<XMLElement>("FN", "", vcard->getFullName()));
	}
	if (!vcard->getGivenName().empty() || !vcard->getFamilyName().empty() || !vcard->getMiddleName().empty() || !vcard->getPrefix().empty() || !vcard->getSuffix().empty()) {
		boost::shared_ptr<XMLElement> nameElement(new XMLElement("N"));
		if (!vcard->getFamilyName().empty()) {
			nameElement->addNode(boost::make_shared<XMLElement>("FAMILY", "", vcard->getFamilyName()));
		}
		if (!vcard->getGivenName().empty()) {
			nameElement->addNode(boost::make_shared<XMLElement>("GIVEN", "", vcard->getGivenName()));
		}
		if (!vcard->getMiddleName().empty()) {
			nameElement->addNode(boost::make_shared<XMLElement>("MIDDLE", "", vcard->getMiddleName()));
		}
		if (!vcard->getPrefix().empty()) {
			nameElement->addNode(boost::make_shared<XMLElement>("PREFIX", "", vcard->getPrefix()));
		}
		if (!vcard->getSuffix().empty()) {
			nameElement->addNode(boost::make_shared<XMLElement>("SUFFIX", "", vcard->getSuffix()));
		}
		queryElement.addNode(nameElement);
	}
	foreach(const VCard::EMailAddress& emailAddress, vcard->getEMailAddresses()) {
		boost::shared_ptr<XMLElement> emailElement(new XMLElement("EMAIL"));
		emailElement->addNode(boost::make_shared<XMLElement>("USERID", "", emailAddress.address));
		if (emailAddress.isHome) {
			emailElement->addNode(boost::make_shared<XMLElement>("HOME"));
		}
		if (emailAddress.isWork) {
			emailElement->addNode(boost::make_shared<XMLElement>("WORK"));
		}
		if (emailAddress.isInternet) {
			emailElement->addNode(boost::make_shared<XMLElement>("INTERNET"));
		}
		if (emailAddress.isPreferred) {
			emailElement->addNode(boost::make_shared<XMLElement>("PREF"));
		}
		if (emailAddress.isX400) {
			emailElement->addNode(boost::make_shared<XMLElement>("X400"));
		}
		queryElement.addNode(emailElement);
	}
	if (!vcard->getNickname().empty()) {
		queryElement.addNode(boost::make_shared<XMLElement>("NICKNAME", "", vcard->getNickname()));
	}
	if (!vcard->getPhoto().empty() || !vcard->getPhotoType().empty()) {
		XMLElement::ref photoElement(new XMLElement("PHOTO"));
		if (!vcard->getPhotoType().empty()) {
			photoElement->addNode(boost::make_shared<XMLElement>("TYPE", "", vcard->getPhotoType()));
		}
		if (!vcard->getPhoto().empty()) {
			photoElement->addNode(boost::make_shared<XMLElement>("BINVAL", "", Base64::encode(vcard->getPhoto())));
		}
		queryElement.addNode(photoElement);
	}
	if (!vcard->getBirthday().is_not_a_date_time()) {
		queryElement.addNode(boost::make_shared<XMLElement>("BDAY", "", dateTimeToString(vcard->getBirthday())));
	}

	foreach(const VCard::Telephone& telephone, vcard->getTelephones()) {
		boost::shared_ptr<XMLElement> telElement(new XMLElement("TEL"));
		telElement->addNode(boost::make_shared<XMLElement>("NUMBER", "", telephone.number));
		if (telephone.isHome) {
			telElement->addNode(boost::make_shared<XMLElement>("HOME"));
		}
		if (telephone.isWork) {
			telElement->addNode(boost::make_shared<XMLElement>("WORK"));
		}
		if (telephone.isVoice) {
			telElement->addNode(boost::make_shared<XMLElement>("VOICE"));
		}
		if (telephone.isFax) {
			telElement->addNode(boost::make_shared<XMLElement>("FAX"));
		}
		if (telephone.isPager) {
			telElement->addNode(boost::make_shared<XMLElement>("PAGER"));
		}
		if (telephone.isMSG) {
			telElement->addNode(boost::make_shared<XMLElement>("MSG"));
		}
		if (telephone.isCell) {
			telElement->addNode(boost::make_shared<XMLElement>("CELL"));
		}
		if (telephone.isVideo) {
			telElement->addNode(boost::make_shared<XMLElement>("VIDEO"));
		}
		if (telephone.isBBS) {
			telElement->addNode(boost::make_shared<XMLElement>("BBS"));
		}
		if (telephone.isModem) {
			telElement->addNode(boost::make_shared<XMLElement>("MODEM"));
		}
		if (telephone.isISDN) {
			telElement->addNode(boost::make_shared<XMLElement>("ISDN"));
		}
		if (telephone.isPCS) {
			telElement->addNode(boost::make_shared<XMLElement>("PCS"));
		}
		if (telephone.isPreferred) {
			telElement->addNode(boost::make_shared<XMLElement>("PREF"));
		}
		queryElement.addNode(telElement);
	}

	foreach(const VCard::Address& address, vcard->getAddresses()) {
		boost::shared_ptr<XMLElement> adrElement = boost::make_shared<XMLElement>("ADR");
		if (!address.poBox.empty()) {
			adrElement->addNode(boost::make_shared<XMLElement>("POBOX", "", address.poBox));
		}
		if (!address.addressExtension.empty()) {
			adrElement->addNode(boost::make_shared<XMLElement>("EXTADD", "", address.addressExtension));
		}
		if (!address.street.empty()) {
			adrElement->addNode(boost::make_shared<XMLElement>("STREET", "", address.street));
		}
		if (!address.locality.empty()) {
			adrElement->addNode(boost::make_shared<XMLElement>("LOCALITY", "", address.locality));
		}
		if (!address.region.empty()) {
			adrElement->addNode(boost::make_shared<XMLElement>("REGION", "", address.region));
		}
		if (!address.postalCode.empty()) {
			adrElement->addNode(boost::make_shared<XMLElement>("PCODE", "", address.postalCode));
		}
		if (!address.country.empty()) {
			adrElement->addNode(boost::make_shared<XMLElement>("CTRY", "", address.country));
		}

		if (address.isHome) {
			adrElement->addNode(boost::make_shared<XMLElement>("HOME"));
		}
		if (address.isWork) {
			adrElement->addNode(boost::make_shared<XMLElement>("WORK"));
		}
		if (address.isPostal) {
			adrElement->addNode(boost::make_shared<XMLElement>("POSTAL"));
		}
		if (address.isParcel) {
			adrElement->addNode(boost::make_shared<XMLElement>("PARCEL"));
		}
		if (address.deliveryType == VCard::DomesticDelivery) {
			adrElement->addNode(boost::make_shared<XMLElement>("DOM"));
		}
		if (address.deliveryType == VCard::InternationalDelivery) {
			adrElement->addNode(boost::make_shared<XMLElement>("INTL"));
		}
		if (address.isPreferred) {
			adrElement->addNode(boost::make_shared<XMLElement>("PREF"));
		}
		queryElement.addNode(adrElement);
	}

	foreach(const VCard::AddressLabel& addressLabel, vcard->getAddressLabels()) {
		boost::shared_ptr<XMLElement> labelElement = boost::make_shared<XMLElement>("LABEL");

		foreach(const std::string& line, addressLabel.lines) {
			labelElement->addNode(boost::make_shared<XMLElement>("LINE", "", line));
		}

		if (addressLabel.isHome) {
			labelElement->addNode(boost::make_shared<XMLElement>("HOME"));
		}
		if (addressLabel.isWork) {
			labelElement->addNode(boost::make_shared<XMLElement>("WORK"));
		}
		if (addressLabel.isPostal) {
			labelElement->addNode(boost::make_shared<XMLElement>("POSTAL"));
		}
		if (addressLabel.isParcel) {
			labelElement->addNode(boost::make_shared<XMLElement>("PARCEL"));
		}
		if (addressLabel.deliveryType == VCard::DomesticDelivery) {
			labelElement->addNode(boost::make_shared<XMLElement>("DOM"));
		}
		if (addressLabel.deliveryType == VCard::InternationalDelivery) {
			labelElement->addNode(boost::make_shared<XMLElement>("INTL"));
		}
		if (addressLabel.isPreferred) {
			labelElement->addNode(boost::make_shared<XMLElement>("PREF"));
		}
		queryElement.addNode(labelElement);
	}

	foreach(const JID& jid, vcard->getJIDs()) {
		queryElement.addNode(boost::make_shared<XMLElement>("JID", "", jid.toString()));
	}

	if (!vcard->getDescription().empty()) {
		queryElement.addNode(boost::make_shared<XMLElement>("DESC", "", vcard->getDescription()));
	}

	foreach(const VCard::Organization& org, vcard->getOrganizations()) {
		boost::shared_ptr<XMLElement> orgElement = boost::make_shared<XMLElement>("ORG");
		if (!org.name.empty()) {
			orgElement->addNode(boost::make_shared<XMLElement>("ORGNAME", "", org.name));
		}
		if (!org.units.empty()) {
			foreach(const std::string& unit, org.units) {
				orgElement->addNode(boost::make_shared<XMLElement>("ORGUNIT", "", unit));
			}
		}
		queryElement.addNode(orgElement);
	}
void SvgSerializer::write(const IfcGeom::BRepElement<double>* o) {
	IfcSchema::IfcBuildingStorey* storey = 0;
	IfcSchema::IfcObjectDefinition* obdef = static_cast<IfcSchema::IfcObjectDefinition*>(file->entityById(o->id()));

#ifndef USE_IFC4
	typedef IfcSchema::IfcRelDecomposes decomposition_element;
#else
	typedef IfcSchema::IfcRelAggregates decomposition_element;
#endif

	while (true) {
		// Iterate over the decomposing element to find the parent IfcBuildingStorey
		decomposition_element::list::ptr decomposes = obdef->Decomposes();
		if (!decomposes->size()) {
			if (obdef->is(IfcSchema::Type::IfcElement)) {
				IfcSchema::IfcRelContainedInSpatialStructure::list::ptr containment = ((IfcSchema::IfcElement*)obdef)->ContainedInStructure();
				if (!containment->size()) {
					break;
				}
				for (IfcSchema::IfcRelContainedInSpatialStructure::list::it it = containment->begin(); it != containment->end(); ++it) {
					IfcSchema::IfcRelContainedInSpatialStructure* container = *it;
					if (container->RelatingStructure() != obdef) {
						obdef = container->RelatingStructure();
					}
				}
			} else {
				break;
			}
		} else {
			for (decomposition_element::list::it it = decomposes->begin(); it != decomposes->end(); ++it) {
				decomposition_element* decompose = *it;
				if (decompose->RelatingObject() != obdef) {
					obdef = decompose->RelatingObject();
				}
			}
		}
		if (obdef->is(IfcSchema::Type::IfcBuildingStorey)) {
			storey = static_cast<IfcSchema::IfcBuildingStorey*>(obdef);
			break;
		}
	}

	if (!storey) return;

	path_object& p = start_path(storey, nameElement(o));

	for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) {
		gp_GTrsf gtrsf = it->Placement();
		
		gp_Trsf o_trsf;
		const std::vector<double>& matrix = o->transformation().matrix().data();
		o_trsf.SetValues(
			matrix[0], matrix[3], matrix[6], matrix[ 9],
			matrix[1], matrix[4], matrix[7], matrix[10], 
			matrix[2], matrix[5], matrix[8], matrix[11]
#if OCC_VERSION_HEX < 0x60800
			, Precision::Angular(), Precision::Confusion()
#endif
		);
		gtrsf.PreMultiply(o_trsf);
		const TopoDS_Shape& s = it->Shape();			
			
		bool trsf_valid = false;
		gp_Trsf trsf;
		try {
			trsf = gtrsf.Trsf();
			trsf_valid = true;
		} catch (...) {}
			
		const TopoDS_Shape moved_shape = trsf_valid
			? BRepBuilderAPI_Transform(s, trsf, true).Shape()
			: BRepBuilderAPI_GTransform(s, gtrsf, true).Shape();
			
		const double inf = std::numeric_limits<double>::infinity();
		double zmin = inf;
		double zmax = -inf;
		{TopExp_Explorer exp(moved_shape, TopAbs_VERTEX);
		for (; exp.More(); exp.Next()) {
			const TopoDS_Vertex& vertex = TopoDS::Vertex(exp.Current());
			gp_Pnt pnt = BRep_Tool::Pnt(vertex);
			if (pnt.Z() < zmin) { zmin = pnt.Z(); }
			if (pnt.Z() > zmax) { zmax = pnt.Z(); }
		}}

		if (section_height) {
			if (zmin > section_height || zmax < section_height) continue;
		} else {
			if (zmin == inf || (zmax - zmin) < 1.) continue;
		}

		const double cut_z = section_height.get_value_or(zmin + 1.);

		// Create a horizontal cross section 1 meter above the bottom point of the shape		
		TopoDS_Shape result = BRepAlgoAPI_Section(moved_shape, gp_Pln(gp_Pnt(0, 0, cut_z), gp::DZ()));

		Handle(TopTools_HSequenceOfShape) edges = new TopTools_HSequenceOfShape();
		Handle(TopTools_HSequenceOfShape) wires = new TopTools_HSequenceOfShape();
		{TopExp_Explorer exp(result, TopAbs_EDGE);
		for (; exp.More(); exp.Next()) {
			 edges->Append(exp.Current());
		}}
		ShapeAnalysis_FreeBounds::ConnectEdgesToWires(edges, 1e-5, false, wires);

		gp_Pnt prev;

		for (int i = 1; i <= wires->Length(); ++i) {
			const TopoDS_Wire& wire = TopoDS::Wire(wires->Value(i));
			write(p, wire);
		}
	}	
}
Beispiel #5
0
void BrowseRequestHandler::dataChanged(const VariablePtr changedData){
	PVSSTRACE(TRACEIN,"BrowseRequestHandler::dataChanged");
	std::vector<SString>	fieldNames; 
	std::vector<int> dipFieldTypes; 
	std::vector<SString> childNames;
	std::vector<int> childTypes;


	TextVar * name = (TextVar *)changedData;
	if (!name){
		return;
	}

	// the overloaded const const char *() operator for TextVAR does not seem to
	// work - so I get a char string by going though the intermediate CharString
	// var
	CharString & charStr = name->getString(); 
	SString nodeName = (const char *)charStr;
	PVSSINFO("Browse request for " << nodeName.getString());
	int nodeType = browser.getNodeInfo(nodeName,fieldNames,dipFieldTypes,childNames,childTypes);

	DpIdValueList *listOfValuesToSend = new DpIdValueList();
	{
		DynVar * fieldNameArray = new DynVar(TEXT_VAR);
		DynVar * pvssFieldTypeArray = new DynVar(INTEGER_VAR);  // holds equiv. PVSS types 
		PVSSINFO("Fields");
		for (unsigned i=0; i < fieldNames.size(); i++){
			TextVar nameElement(fieldNames[i]);
			fieldNameArray->append(nameElement);
			const TConv * converter = TMap::findDipToDpeConverterFor(dipFieldTypes[i]);
			IntegerVar typeElement(converter->getDPEtypeID());
			pvssFieldTypeArray->append(typeElement);
			PVSSINFO((const char *)nameElement << " data type " << (longlong)typeElement.getValue());
		}
		listOfValuesToSend->appendItem(fieldNameDpeID, fieldNameArray);
		listOfValuesToSend->appendItem(fieldTypeDpeID, pvssFieldTypeArray);
	}
		
	{
		DynVar * childNameArray = new DynVar(TEXT_VAR);
		DynVar * childTypeArray = new DynVar(INTEGER_VAR);  // indicates branch/node
		PVSSINFO("Children");
		for (unsigned i=0; i < childNames.size(); i++){
			TextVar nameElement(childNames[i]);
			childNameArray->append(nameElement);
			IntegerVar typeElement(childTypes[i]);
			childTypeArray->append(typeElement);
			PVSSINFO((const char *)nameElement << " node type " << (longlong)typeElement.getValue());
		}
		listOfValuesToSend->appendItem(childNameDpeID, childNameArray);
		listOfValuesToSend->appendItem(childTypeDpeID, childTypeArray);
	}
	
	{
		IntegerVar status(nodeType);
		listOfValuesToSend->appendItem(browseStatusDpeID, status);
	}

	BC_CTime tmpTime;  // gives me current time in seconds
	TimeVar pvssFormatTime(tmpTime,0);
	
	TimeVar currentTime;
	BC_CTime timeSeconds;
	short timeMSec;
	currentTime.getValue(timeSeconds, timeMSec); 
	DipLong timeInMs = ((DipLong)timeSeconds.ElapsedSeconds() * 1000) + timeMSec;

	apiManager.queueDPEDataReadyForUpdate(listOfValuesToSend, timeInMs); // can't return values from inside handler - so we queue it to be processed later

	PVSSTRACE(TRACEOUT,"BrowseRequestHandler::dataChanged");
}
std::string VCardSerializer::serializePayload(boost::shared_ptr<VCard> vcard)  const {
	XMLElement queryElement("vCard", "vcard-temp");
	if (!vcard->getVersion().empty()) {
		boost::shared_ptr<XMLElement> versionElement(new XMLElement("VERSION"));
		versionElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getVersion())));
		queryElement.addNode(versionElement);
	}
	if (!vcard->getFullName().empty()) {
		boost::shared_ptr<XMLElement> fullNameElement(new XMLElement("FN"));
		fullNameElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getFullName())));
		queryElement.addNode(fullNameElement);
	}
	if (!vcard->getGivenName().empty() || !vcard->getFamilyName().empty() || !vcard->getMiddleName().empty() || !vcard->getPrefix().empty() || !vcard->getSuffix().empty()) {
		boost::shared_ptr<XMLElement> nameElement(new XMLElement("N"));
		if (!vcard->getFamilyName().empty()) {
			boost::shared_ptr<XMLElement> familyNameElement(new XMLElement("FAMILY"));
			familyNameElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getFamilyName())));
			nameElement->addNode(familyNameElement);
		}
		if (!vcard->getGivenName().empty()) {
			boost::shared_ptr<XMLElement> givenNameElement(new XMLElement("GIVEN"));
			givenNameElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getGivenName())));
			nameElement->addNode(givenNameElement);
		}
		if (!vcard->getMiddleName().empty()) {
			boost::shared_ptr<XMLElement> middleNameElement(new XMLElement("MIDDLE"));
			middleNameElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getMiddleName())));
			nameElement->addNode(middleNameElement);
		}
		if (!vcard->getPrefix().empty()) {
			boost::shared_ptr<XMLElement> prefixElement(new XMLElement("PREFIX"));
			prefixElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getPrefix())));
			nameElement->addNode(prefixElement);
		}
		if (!vcard->getSuffix().empty()) {
			boost::shared_ptr<XMLElement> suffixElement(new XMLElement("SUFFIX"));
			suffixElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getSuffix())));
			nameElement->addNode(suffixElement);
		}
		queryElement.addNode(nameElement);
	}
	foreach(const VCard::EMailAddress& emailAddress, vcard->getEMailAddresses()) {
		boost::shared_ptr<XMLElement> emailElement(new XMLElement("EMAIL"));
		boost::shared_ptr<XMLElement> userIDElement(new XMLElement("USERID"));
		userIDElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(emailAddress.address)));
		emailElement->addNode(userIDElement);
		if (emailAddress.isHome) {
			emailElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("HOME")));
		}
		if (emailAddress.isWork) {
			emailElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("WORK")));
		}
		if (emailAddress.isInternet) {
			emailElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("INTERNET")));
		}
		if (emailAddress.isPreferred) {
			emailElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("PREF")));
		}
		if (emailAddress.isX400) {
			emailElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("X400")));
		}
		queryElement.addNode(emailElement);
	}
	if (!vcard->getNickname().empty()) {
		boost::shared_ptr<XMLElement> nickElement(new XMLElement("NICKNAME"));
		nickElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getNickname())));
		queryElement.addNode(nickElement);
	}
	if (!vcard->getPhoto().isEmpty() || !vcard->getPhotoType().empty()) {
		XMLElement::ref photoElement(new XMLElement("PHOTO"));
		if (!vcard->getPhotoType().empty()) {
			XMLElement::ref typeElement(new XMLElement("TYPE"));
			typeElement->addNode(XMLTextNode::ref(new XMLTextNode(vcard->getPhotoType())));
			photoElement->addNode(typeElement);
		}
		if (!vcard->getPhoto().isEmpty()) {
			XMLElement::ref binvalElement(new XMLElement("BINVAL"));
			binvalElement->addNode(XMLTextNode::ref(new XMLTextNode(Base64::encode(vcard->getPhoto()))));
			photoElement->addNode(binvalElement);
		}
		queryElement.addNode(photoElement);
	}
	if (!vcard->getUnknownContent().empty()) {
		queryElement.addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(vcard->getUnknownContent())));
	}
	return queryElement.serialize();
}