void RoutePlanner::activateDebugDraw(bool activate) { if (activate) { debugGraphicObject = GraphicEngine::getInstance()->createObject(getId()); std::list<RouteNode*> nodes = map.getItems(); for (std::list<RouteNode*>::iterator i = nodes.begin(); i != nodes.end(); i++) { //Draw node RouteNode* node = *i; GraphicObject* object = debugGraphicObject->createChild(WasVec3d(node->position.x, 0, -node->position.y)); object->scale(WasVec3d(0.5, 0.5, 0.5)); Entity* entity = object->createEntity(PT_CUBE); entity->setColor(ColourValue::BLUE); //Draw paths Vertex v1 = {node->position.x, 0, -node->position.y}; for (std::map<int, int>::iterator j = node->routeMap.begin(); j != node->routeMap.end(); j++) { if (j->first == j->second) { MeshPrototype prototype(WASABI_LINES); Face face; Vertex v2 = {getNode(j->first)->position.x, 0, - getNode(j->first)->position.y}; face.addVertex(v1); face.addVertex(v2); prototype.addFace(face); Entity* entity = debugGraphicObject->createEntity(prototype); entity->setColor(ColourValue::BLUE); } } } } else if (debugGraphicObject != NULL) { GraphicEngine::getInstance()->destroyObject(debugGraphicObject); } debugDraw = activate; }
GraphicObject* GraphicUndoUtilities::getObject(const GraphicGroup* pGroup, const string& objectId) { if ((pGroup == NULL) || (objectId.empty() == true)) { return NULL; } const list<GraphicObject*>& objects = pGroup->getObjects(); for (list<GraphicObject*>::const_iterator iter = objects.begin(); iter != objects.end(); ++iter) { GraphicObject* pObject = *iter; if (pObject != NULL) { if (pObject->getId() == objectId) { return pObject; } } GraphicGroup* pChildGroup = dynamic_cast<GraphicGroup*>(*iter); if (pChildGroup != NULL) { GraphicObject* pGroupObject = getObject(pChildGroup, objectId); if (pGroupObject != NULL) { return pGroupObject; } } } return NULL; }
GraphicObject* GraphicPencil::Create(CPoint point, COLORREF c, int thickness, int pattern) { GraphicObject* pencil = new GraphicPencil; pencil->AddPoint(point); pencil->setColor(c); pencil->setThickness(thickness); pencil->setPattern(pattern); return pencil; }
// ----------------------------------------------------------------- // Name : getNextObjectAt // ----------------------------------------------------------------- MapObject * Map::getNextObjectAt(int x, int y, u32 type) { GraphicObject * pObj = (GraphicObject*) m_pTiles[x][y]->m_pMapObjects->getNext(0); while (pObj != NULL) { if (pObj->getType() & type) return (MapObject*) pObj; pObj = (GraphicObject*) m_pTiles[x][y]->m_pMapObjects->getNext(0); } return NULL; }
void GroupUngroupGraphicObjects::ungroup() { GraphicLayer* pLayer = dynamic_cast<GraphicLayer*>(getSessionItem()); if ((pLayer != NULL) && (mGroupId.empty() == false)) { string viewId; View* pView = pLayer->getView(); if (pView != NULL) { viewId = pView->getId(); } GraphicGroup* pGroup = dynamic_cast<GraphicGroup*>(GraphicUndoUtilities::getObject(viewId, pLayer->getId(), mGroupId)); if (pGroup != NULL) { list<GraphicObject*> selectedObjects; pLayer->getSelectedObjects(selectedObjects); pLayer->deselectAllObjects(); pLayer->selectObject(pGroup); pLayer->ungroupSelection(); list<GraphicObject*> objects; pLayer->getSelectedObjects(objects); mObjectIds.clear(); for (list<GraphicObject*>::iterator iter = objects.begin(); iter != objects.end(); ++iter) { GraphicObject* pObject = *iter; if (pObject != NULL) { string objectId = pObject->getId(); if (objectId.empty() == false) { mObjectIds.push_back(objectId); } } } for (list<GraphicObject*>::iterator iter = selectedObjects.begin(); iter != selectedObjects.end(); ++iter) { GraphicObject* pObject = *iter; if ((pObject != NULL) && (pObject != pGroup)) { pLayer->selectObject(pObject); } } } } }
/** * @inheritDoc */ void GraphicScene::ProcessRange(u32 begin, u32 end) { auto start = m_pObjects.begin() + begin; for (auto iterator = start; iterator < start + end; iterator++) { GraphicObject* pObject = static_cast<GraphicObject*>(iterator->second); // Update objects based on paused state // TODO maybe not pause some objects ? if (!m_bPause) { // Process this object pObject->Update(m_fDeltaTime); } } }
QList<core::GraphicObject *> core::Connector::removeIgnoredObjects(const QList<GraphicObject *> &list) const { GraphicObject *obj; QList<GraphicObject*> returnedList = list; for(auto i = 0; i < returnedList.size(); i++){ obj = returnedList[i]; if(obj->type() == gotConnector || obj == beginObject){ returnedList.removeOne(obj); i--; } } return returnedList; }
// Adds a fade in animation // lower numerical value for priority means a higher priority void Animator::addFadeAnimation (GraphicObject &object, int time, int priority, float startAlpha, float endAlpha) { Animation newAnimation; newAnimation.time = time; // Alpha changes newAnimation.startAlpha = startAlpha; newAnimation.endAlpha = endAlpha; // Position changeos newAnimation.startX = object.getX (); newAnimation.startY = object.getY (); newAnimation.endX = object.getX (); newAnimation.endY = object.getY (); newAnimation.priority = priority; newAnimation.timer.start (); animationQueue.push (newAnimation); }
void CreateDestroyGraphicObject::createObject() { if (mpClone == NULL) { return; } GraphicGroup* pGroup = dynamic_cast<GraphicGroup*>(getSessionItem()); if (pGroup != NULL) { string oldObjectId = mObjectId; mObjectId.clear(); GraphicObject* pObject = pGroup->addObject(mpClone->getGraphicObjectType()); if (pObject != NULL) { mObjectId = pObject->getId(); GraphicObjectImp* pObjectImp = dynamic_cast<GraphicObjectImp*>(pObject); if (pObjectImp != NULL) { pObjectImp->replicateObject(dynamic_cast<GraphicObject*>(mpClone)); } if (mIndex != -1) { GraphicGroupImp* pGroupImp = dynamic_cast<GraphicGroupImp*>(pGroup); if (pGroupImp != NULL) { GraphicLayerImp* pLayer = dynamic_cast<GraphicLayerImp*>(pGroupImp->getLayer()); if (pLayer != NULL) { pLayer->setObjectStackingIndex(pObject, mIndex); } } } } emit sessionItemChanged(oldObjectId, mObjectId); } }
// Adds a slide in effect void Animator::addSlideInAnimation (GraphicObject &object, int time, int priority, int startX, int startY, int endX, int endY) { Animation newAnimation; newAnimation.time = time; // Alpha changes newAnimation.startAlpha = object.getAlpha(); newAnimation.endAlpha = object.getAlpha(); // Position changes newAnimation.startX = startX; newAnimation.startY = startY; newAnimation.endX = endX; newAnimation.endY = endY; newAnimation.priority = priority; newAnimation.timer.start (); animationQueue.push (newAnimation); }
GroupUngroupGraphicObjects::GroupUngroupGraphicObjects(GraphicLayer* pLayer, GraphicGroup* pGroup) : UndoAction(pLayer) { if (pGroup != NULL) { const list<GraphicObject*>& objects = pGroup->getObjects(); for (list<GraphicObject*>::const_iterator iter = objects.begin(); iter != objects.end(); ++iter) { GraphicObject* pObject = *iter; if (pObject != NULL) { string objectId = pObject->getId(); if (objectId.empty() == false) { mObjectIds.push_back(objectId); } } } mGroupId = pGroup->getId(); } }
void GameObject::setViewPosition( GraphicObject& obj, const ProtoObject::View & v, float x, float y, float z) { float dx = 0, dy = 0, dz = 0; double modelSize[3] = { obj.bounds().max[0] - obj.bounds().min[0], obj.bounds().max[1] - obj.bounds().min[1], obj.bounds().max[2] - obj.bounds().min[2] }; const int * align = v.align; double alignSize = v.alignSize; dx = modelSize[0]*obj.sizeX()*align[0]*alignSize; dy = modelSize[1]*obj.sizeY()*align[1]*alignSize; dz = modelSize[2]*obj.sizeZ()*align[2]*alignSize; obj.setPosition( x+dx, y+dy, z+dz ); }
int ShapeFile::getAttributeIndex(const GraphicObject& graphicObject, const DynamicObject& dynObj) const { const string objectId = graphicObject.getId(); VERIFYRV(objectId.empty() == false, -1); DataVariant idsVar = dynObj.getAttribute(graphicObjectIdAttrName); vector<string> objectIds; idsVar.getValue(objectIds); for (vector<string>::size_type i = 0; i < objectIds.size(); ++i) { if (objectIds[i] == objectId) { return static_cast<int>(i); } } return -1; }
bool TiffDetails::addGeoKeys(TIFF* pOut, int width, int height, const SessionItem *pItem) { if ((pOut == NULL) || (width == 0) || (height == 0)) { return false; } const View* pInputView = dynamic_cast<const View*>(pItem); if (pInputView == NULL) { return false; } RasterElement* pGeoreferencedRaster = NULL; // First raster element we find with georeferencing information const ProductView* pView = dynamic_cast<const ProductView*>(pInputView); if (pView != NULL) { AnnotationLayer* pAnno = pView->getLayoutLayer(); if (pAnno == NULL) { return false; } /* NOTE: If we find more than one SpatialDataView with a georeferenced RasterElement, we will only provide geo-data for the FIRST one - because two views could theoretically screw up the geo-data if one is in Australia and the other in Canada. */ // get all the view objects std::list<GraphicObject*> objs; pAnno->getObjects(VIEW_OBJECT, objs); // for every object, find the data set with a geocoord matrix for (std::list<GraphicObject*>::iterator it = objs.begin(); it != objs.end(); ++it) { GraphicObject* pObj = *it; if (pObj != NULL) { SpatialDataView* pSpView = dynamic_cast<SpatialDataView*>(pObj->getObjectView()); if (pSpView != NULL) { LayerList* pLayerList = pSpView->getLayerList(); if (pLayerList != NULL) { RasterElement* pRaster = pLayerList->getPrimaryRasterElement(); if (pRaster != NULL && pRaster->isGeoreferenced()) { pGeoreferencedRaster = pRaster; break; } } } } } } const SpatialDataView* pSpView = dynamic_cast<const SpatialDataView*>(pInputView); if (pSpView != NULL) { LayerList* pLayerList = pSpView->getLayerList(); if (pLayerList != NULL) { RasterElement* pRaster = pLayerList->getPrimaryRasterElement(); if (pRaster != NULL && pRaster->isGeoreferenced()) { pGeoreferencedRaster = pRaster; } } } if (pGeoreferencedRaster == NULL) { return false; } GTIF* pGtif = GTIFNew(pOut); if (pGtif == NULL) { return false; } LocationType lowerLeft; LocationType upperLeft; LocationType upperRight; LocationType lowerRight; pInputView->getVisibleCorners(lowerLeft, upperLeft, upperRight, lowerRight); LocationType latLong; //get the lat/long's (0,0) latLong = pGeoreferencedRaster->convertPixelToGeocoord(upperLeft); double ll1y = latLong.mY; //delta long double ll1x = latLong.mX; //delta lat latLong = pGeoreferencedRaster->convertPixelToGeocoord(upperRight); double ll2y = latLong.mY; //long double ll2x = latLong.mX; //lat latLong = pGeoreferencedRaster->convertPixelToGeocoord(lowerLeft); double ll3y = latLong.mY; //long double ll3x = latLong.mX; //lat //compute transformation Matrix values //added slight modification, must divide by magnitude double a = (ll2y - ll1y) / width; double b = (ll3y - ll1y) / height; double d = (ll1y); double e = (ll2x - ll1x) / width; double f = (ll3x - ll1x) / height; double h = (ll1x); double tMatrix[16] = { a, b, 0.0, d, e, f, 0.0, h, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; TIFFSetField(pOut, GTIFF_TRANSMATRIX, 16, tMatrix); GTIFKeySet(pGtif, GTRasterTypeGeoKey, TYPE_SHORT, 1, RasterPixelIsArea); GTIFKeySet(pGtif, GTModelTypeGeoKey, TYPE_SHORT, 1, ModelGeographic); GTIFKeySet(pGtif, GeographicTypeGeoKey, TYPE_SHORT, 1, GCS_WGS_84); // Here we violate the GTIF abstraction to retarget on another file. // We should just have a function for copying tags from one GTIF object // to another. pGtif->gt_tif = pOut; pGtif->gt_flags |= FLAG_FILE_MODIFIED; // Install keys and tags GTIFWriteKeys(pGtif); GTIFFree(pGtif); return true; }
bool ChangeUpDirection::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { if (pInArgList == NULL || pOutArgList == NULL) { return false; } ProgressTracker progress(pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()), "Rotating data.", "app", "{11adadb9-c133-49de-8cf5-a16372da2578}"); RasterElement* pData = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); if (pData == NULL) { progress.report("No data element specified.", 0, ERRORS, true); return false; } bool display = false; if (!pInArgList->getPlugInArgValue("Display Results", display)) { progress.report("Unsure if results should be displayed. Invalid argument.", 0, ERRORS, true); return false; } double rotation = 0.0; SpatialDataView* pOrigView = NULL; if (isBatch()) { if (!pInArgList->getPlugInArgValue("Rotation", rotation)) { progress.report("No rotation specified.", 0, ERRORS, true); return false; } } else { pOrigView = pInArgList->getPlugInArgValue<SpatialDataView>(Executable::ViewArg()); if (pOrigView == NULL) { progress.report("No view specified.", 0, ERRORS, true); return false; } GraphicLayer* pLayer = dynamic_cast<GraphicLayer*>(pOrigView->getActiveLayer()); if (pLayer == NULL) { pLayer = dynamic_cast<GraphicLayer*>(pOrigView->getTopMostLayer(ANNOTATION)); } GraphicObject* pArrow = NULL; if (pLayer != NULL) { std::list<GraphicObject*> objects; pLayer->getObjects(ARROW_OBJECT, objects); if (!objects.empty()) { pArrow = objects.back(); } if (objects.size() > 1) { progress.report("Multiple arrow objects found. Using the most recently added one.", 0, WARNING, true); } } if (pArrow == NULL) { progress.report("Unable to locate up direction. Add an arrow annotation and re-run this plugin.", 0, ERRORS, true); return false; } LocationType ur = pArrow->getUrCorner(); LocationType ll = pArrow->getLlCorner(); double xlen = ur.mX - ll.mX; double ylen = ur.mY - ll.mY; // Initial rotatation value. The 90 degrees is due to the difference // in the "0 point" (right vs. up). Also account for explicit rotation // of the annotation object. Convert this to radians. rotation = GeoConversions::convertDegToRad(90 + pArrow->getRotation()); // Determine a rotation adjustment based on the bounding box rotation += atan2(ylen, xlen); } progress.report("Rotating data.", 10, NORMAL); ModelResource<RasterElement> pRotated(pData->copyShallow(pData->getName() + "_rotated", pData->getParent())); if (pRotated.get() == NULL) { progress.report("Unable to create destination raster element.", 0, ERRORS, true); return false; } int defaultBadValue(0); // the rotate method will handle setting the default bad values into the rotated raster if (!RasterUtilities::rotate(pRotated.get(), pData, rotation, defaultBadValue, INTERP_NEAREST_NEIGHBOR, progress.getCurrentProgress(), &mAbort)) { // error message already reported by rotate() return false; } pOutArgList->setPlugInArgValue("Rotated Element", pRotated.get()); if (display) { SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>( Service<DesktopServices>()->createWindow(pRotated->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView* pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); if (pView == NULL) { Service<DesktopServices>()->deleteWindow(pWindow); progress.report("Unable to create view.", 0, ERRORS, true); return false; } pView->setPrimaryRasterElement(pRotated.get()); RasterLayer* pLayer = NULL; { // scope UndoLock lock(pView); pLayer = static_cast<RasterLayer*>(pView->createLayer(RASTER, pRotated.get())); } if (pLayer == NULL) { //#pragma message(__FILE__ "(" STRING(__LINE__) ") : warning : This would be cleaner with a WindowResource. If one " \ // "becomes available, use it instead. (tclarke)") Service<DesktopServices>()->deleteWindow(pWindow); progress.report("Unable to create layer.", 0, ERRORS, true); return false; } pOutArgList->setPlugInArgValue("View", pView); } pRotated.release(); progress.report("Rotation complete.", 100, NORMAL); progress.upALevel(); return true; }
void Glowny_kontroler::Start() { GraphicObject obj; obj.loadOBJ("models/megahuge_t1.obj", "grafiki/tex1.bmp"); obj.pos.z = 0.0; // czołg nie unosi sie w powietrzu - czemu nie jest widoczny na początku domyślcie sie sami (bo ja nie mam zielonego pojęcia) (-20.0) obj.Color[0] = 0.0; // zmiana koloru czołgu - dla celów testowych // TESTING AREA !!! GraphicObject test_obj_1; // fioletowy test_obj_1.loadOBJ("models/megahuge_t1.obj", "grafiki/tex1.bmp"); test_obj_1.pos.x = 30.0; test_obj_1.pos.y = 10.0; // test_obj_1.pos.z = 10.0; test_obj_1.Color[1] = 0.5; GraphicObject test_obj_2; // szary test_obj_2.loadOBJ("models/megahuge_t1.obj", "grafiki/tex1.bmp"); test_obj_2.pos.x = -1.488228; test_obj_2.pos.y = 3.262749; // test_obj_2.pos.z = 10.0; test_obj_2.Color[2] = 1.0; RendController::init(_objects); obj.SetDisplay(); _objects->push_back(obj); // TESTING test_obj_1.SetDisplay(); _objects->push_back(test_obj_1); test_obj_2.SetDisplay(); _objects->push_back(test_obj_2); //static const GLfloat g_vertex_buffer_data[] = { // -100.0f, -100.0f, 10.0f, // 100.0f, 100.0f, 10.0f, // -100.0f, 100.0f, 10.0f, // -100.0f, -100.0f, 10.0f, // 100.0f, 100.0f, 10.0f, // 100.0f, -100.0f, 10.0f, //}; // //GLuint vertexbuffer; //glGenBuffers(1, &vertexbuffer); //glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); //glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); //glEnableVertexAttribArray(0); //glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); //glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); //glDrawArrays(GL_TRIANGLES, 0, 6); // Starting from vertex 0; 3 vertices total -> 1 triangle //glDisableVertexAttribArray(0); glutMainLoop(); //bool the_end = false; //GameServer server; //Klient klient(_objects); ////poniższy kod odpowiada za uruchomienie serwera i klienta ////std::thread first(&GameServer::Start, server); ////std::thread second(&Klient::Start, klient); ////first.join(); ////second.join(); }
void GameObject::setViewSize( GraphicObject &obj, const ProtoObject::View & v, float x, float y, float z ) { const double *s = v.size; obj.setSize(s[0]*x, s[1]*y, s[2]*z); }
void EastArrowObjectImp::orient() { if (isOriented() == true) { return; } GraphicLayer* pLayer = NULL; pLayer = getLayer(); if (pLayer == NULL) { return; } View* pView = NULL; pView = pLayer->getView(); if (pView == NULL) { return; } SpatialDataView* pSpatialDataView = NULL; if (pView->isKindOf("SpatialDataView") == true) { pSpatialDataView = static_cast<SpatialDataView*> (pView); } else if (pView->isKindOf("ProductView") == true) { ProductView* pProductView = static_cast<ProductView*> (pView); GraphicLayer* pLayoutLayer = NULL; pLayoutLayer = pProductView->getLayoutLayer(); if (pLayoutLayer == pLayer) { list<GraphicObject*> viewObjects; pLayoutLayer->getObjects(VIEW_OBJECT, viewObjects); list<GraphicObject*>::iterator iter = viewObjects.begin(); while (iter != viewObjects.end()) { GraphicObject* pObject = *iter; if (pObject != NULL) { View* pObjectView = pObject->getObjectView(); if (pObjectView != NULL) { if (pObjectView->isKindOf("SpatialDataView") == true) { pSpatialDataView = static_cast<SpatialDataView*> (pObjectView); } } } ++iter; } } } if (pSpatialDataView == NULL) { return; } LayerList* pLayerList = pSpatialDataView->getLayerList(); VERIFYNRV(pLayerList != NULL); RasterElement* pRaster = pLayerList->getPrimaryRasterElement(); VERIFYNRV(pRaster != NULL); if (!pRaster->isGeoreferenced()) { return; } // Calculate the angle of the object relative to the pixel coordinates updateHandles(); LocationType pixelStart = mHandles[7]; ProductView* pProductView = dynamic_cast<ProductView*> (pView); if (pProductView != NULL) { // Convert to the screen coordinate system double dScreenX = 0; double dScreenY = 0; pLayer->translateDataToWorld(pixelStart.mX, pixelStart.mY, pixelStart.mX, pixelStart.mY); pProductView->translateWorldToScreen(pixelStart.mX, pixelStart.mY, dScreenX, dScreenY); // Convert to the spatial data view coordinate system pSpatialDataView->translateScreenToWorld(dScreenX, dScreenY, pixelStart.mX, pixelStart.mY); pLayer->translateWorldToData(pixelStart.mX, pixelStart.mY, pixelStart.mX, pixelStart.mY); } double dAngle; if (GeoAlgorithms::getAngleToNorth(pRaster, dAngle, pixelStart) == false) { return; } // Update the angle if the object is in the layout layer if (pProductView != NULL) { // Rotation dAngle -= pSpatialDataView->getRotation(); // Pitch double dPitch = pSpatialDataView->getPitch(); if (dPitch > 0.0) { dAngle *= -1.0; } } // Rotate the object setRotation(dAngle); // Update the orientation flag DirectionalArrowObjectImp::orient(); }
//--------------------------------------------------------------------------- void __fastcall TMainForm::ParseJSON (const UnicodeString& fileName) { TStringList *jsonText = new TStringList; jsonText->LoadFromFile(fileName); TBytes jsonBytes = TEncoding::UTF8->GetBytes(jsonText->Text); delete jsonText; TJSONObject *json = new TJSONObject; json->Parse(jsonBytes, 0); TJSONObject *topObjectValueObj; // Points topObjectValueObj = parseJsonValue(json->Get("points")->JsonValue); for (int i = 0; i < topObjectValueObj->Size(); ++i) { TJSONPair *pair = topObjectValueObj->Get(i); TJSONArray *array = jsonArrayFromPair(pair); // Vertice *point = new Vertice(INTVALARR(array, 0), // INTVALARR(array, 1), // INTVALARR(array, 2)); // // points[pair->JsonString->Value()] = point; } delete topObjectValueObj; // Edges topObjectValueObj = parseJsonValue(json->Get("edges")->JsonValue); map<UnicodeString, TColor> *colors = new map<UnicodeString, TColor>; (*colors)["red"] = clRed; (*colors)["black"] = clBlack; (*colors)["green"] = clGreen; (*colors)["blue"] = clBlue; (*colors)["fuchsia"] = clFuchsia; (*colors)["lime"] = clLime; for (int i = 0; i < topObjectValueObj->Size(); ++i) { TJSONPair *pair = topObjectValueObj->Get(i); TJSONObject *object = parseJsonValue(pair->JsonValue); TJSONArray *array = jsonArrayFromPair(object->Get("vertices")); // Edge *edge = new Edge (points[STRVALARR(array, 0)], points[STRVALARR(array, 1)]); // // if (object->Get("color")) { // edge->setPen((*colors)[STRVALOBJ(object, "color")], 1, psSolid); // } // // edges[pair->JsonString->Value()] = edge; } delete colors; delete topObjectValueObj; // Objects topObjectValueObj = parseJsonValue(json->Get("objects")->JsonValue); for (int i = 0; i < topObjectValueObj->Size(); ++i) { TJSONPair *pair = topObjectValueObj->Get(i); TJSONObject *object = parseJsonValue(pair->JsonValue); TJSONArray *array = jsonArrayFromPair(object->Get("edges")); GraphicObject *graphicObject = new GraphicObject; for (int j = 0; j < array->Size(); ++j) { graphicObject->addEdge(edges[STRVALARR(array, j)]); } objects[pair->JsonString->Value()] = graphicObject; } delete topObjectValueObj; }
void Kml::generatePolygonalLayer(const GraphicLayer* pGraphicLayer, bool visible, int order, const Layer* pGeoLayer) { VERIFYNRV(pGeoLayer != NULL); if (pGraphicLayer == NULL) { return; } RasterElement* pGeoElement = dynamic_cast<RasterElement*>(pGeoLayer->getDataElement()); mXml.pushAddPoint(mXml.addElement("Folder")); string name = pGraphicLayer->getDisplayName(); if (name.empty()) { name = pGraphicLayer->getName(); } mXml.addText(name, mXml.addElement("name")); mXml.addText(pGraphicLayer->getDisplayText(), mXml.addElement("description")); mXml.addText(visible ? "1" : "0", mXml.addElement("visibility")); list<GraphicObject*> objects; pGraphicLayer->getObjects(objects); for (list<GraphicObject*>::const_iterator object = objects.begin(); object != objects.end(); ++object) { GraphicObject* pObject = *object; if (pObject == NULL) { continue; } mXml.pushAddPoint(mXml.addElement("Placemark")); mXml.addText(pObject->getName(), mXml.addElement("name")); mXml.addText(pObject->isVisible() ? "1" : "0", mXml.addElement("visibility")); mXml.pushAddPoint(mXml.addElement("Style")); mXml.pushAddPoint(mXml.addElement("PolyStyle")); ColorType c = pObject->getFillColor(); QChar fc('0'); mXml.addText(QString("%1%2%3%4").arg(c.mAlpha, 2, 16, fc).arg(c.mBlue, 2, 16, fc).arg( c.mGreen, 2, 16, fc).arg(c.mRed, 2, 16, fc).toAscii().data(), mXml.addElement("color")); mXml.addText(pObject->getLineState() ? "1" : "0", mXml.addElement("outline")); mXml.addText(pObject->getFillState() ? "1" : "0", mXml.addElement("fill")); mXml.popAddPoint(); // PolyStyle mXml.pushAddPoint(mXml.addElement("LineStyle")); c = pObject->getLineColor(); mXml.addText(QString("%1%2%3%4").arg(c.mAlpha, 2, 16, fc).arg(c.mBlue, 2, 16, fc).arg( c.mGreen, 2, 16, fc).arg(c.mRed, 2, 16, fc).toAscii().data(), mXml.addElement("color")); mXml.addText(StringUtilities::toXmlString(pObject->getLineWidth()), mXml.addElement("width")); mXml.popAddPoint(); // LineStyle mXml.popAddPoint(); // Style switch (pObject->getGraphicObjectType()) { case MULTIPOINT_OBJECT: { mXml.pushAddPoint(mXml.addElement("MultiGeometry")); vector<LocationType> vertices = static_cast<MultipointObject*>(pObject)->getVertices(); for (vector<LocationType>::const_iterator vertex = vertices.begin(); vertex != vertices.end(); ++vertex) { mXml.pushAddPoint(mXml.addElement("Point")); mXml.addText(QString::number(order).toAscii().data(), mXml.addElement("drawOrder")); LocationType geo = pGeoElement->convertPixelToGeocoord(*vertex); mXml.addText(QString("%1,%2").arg(geo.mY, 0, 'f', 10).arg(geo.mX, 0, 'f', 10).toAscii().data(), mXml.addElement("coordinates")); mXml.popAddPoint(); // Point } mXml.popAddPoint(); break; } case LINE_OBJECT: case POLYLINE_OBJECT: case HLINE_OBJECT: case VLINE_OBJECT: case ROW_OBJECT: case COLUMN_OBJECT: { mXml.pushAddPoint(mXml.addElement("LineString")); mXml.addText(QString::number(order).toAscii().data(), mXml.addElement("drawOrder")); mXml.addText("1", mXml.addElement("tessellate")); QStringList coords; vector<LocationType> vertices; if (pObject->getGraphicObjectType() == POLYLINE_OBJECT) { vertices = static_cast<PolylineObject*>(pObject)->getVertices(); } else { LocationType ll = pObject->getLlCorner(); LocationType ur = pObject->getUrCorner(); vertices.push_back(ll); vertices.push_back(ur); } for (vector<LocationType>::const_iterator vertex = vertices.begin(); vertex != vertices.end(); ++vertex) { LocationType geo = pGeoElement->convertPixelToGeocoord(*vertex); coords << QString("%1,%2").arg(geo.mY, 0, 'f', 10).arg(geo.mX, 0, 'f', 10); } mXml.addText(coords.join(" ").toAscii().data(), mXml.addElement("coordinates")); mXml.popAddPoint(); // LineString break; } case RECTANGLE_OBJECT: case TRIANGLE_OBJECT: case POLYGON_OBJECT: { mXml.pushAddPoint(mXml.addElement("Polygon")); mXml.addText(QString::number(order).toAscii().data(), mXml.addElement("drawOrder")); mXml.addText("1", mXml.addElement("tessellate")); mXml.pushAddPoint(mXml.addElement("LinearRing", mXml.addElement("outerBoundaryIs"))); QStringList coords; vector<LocationType> vertices; LocationType ll = pObject->getLlCorner(); LocationType ur = pObject->getUrCorner(); LocationType center = (ll + ur); center.mX /= 2.0; center.mY /= 2.0; if (pObject->getGraphicObjectType() == RECTANGLE_OBJECT) { vertices.push_back(ll); vertices.push_back(LocationType(ll.mX, ur.mY)); vertices.push_back(ur); vertices.push_back(LocationType(ur.mX, ll.mY)); } else if (pObject->getGraphicObjectType() == TRIANGLE_OBJECT) { double apex = pObject->getApex(); vertices.push_back(ll); vertices.push_back(LocationType(ur.mX, ll.mY)); vertices.push_back(LocationType(ll.mX + apex * (ur.mX - ll.mX), ur.mY)); vertices.push_back(ll); } else { vertices = static_cast<PolygonObject*>(pObject)->getVertices(); } QPointF qcenter(center.mX, center.mY); QMatrix matrix; matrix.rotate(pObject->getRotation()); for (vector<LocationType>::const_iterator vertex = vertices.begin(); vertex != vertices.end(); ++vertex) { QPointF point(vertex->mX - center.mX, vertex->mY - center.mY); point = point * matrix; point += qcenter; LocationType geo = pGeoElement->convertPixelToGeocoord(LocationType(point.x(), point.y())); coords << QString("%1,%2").arg(geo.mY, 0, 'f', 10).arg(geo.mX, 0, 'f', 10); } mXml.addText(coords.join(" ").toAscii().data(), mXml.addElement("coordinates")); mXml.popAddPoint(); // LinearRing mXml.popAddPoint(); // Polygon break; } default: // not supported break; } mXml.popAddPoint(); // Placemark } mXml.popAddPoint(); // Folder }
string TextObjectImp::getSubstitutedText() { string txt = getText(); DataElement* pParent = getElement(); pParent = (pParent == NULL) ? NULL : pParent->getParent(); DataDescriptor* pParentDesc = (pParent == NULL) ? NULL : pParent->getDataDescriptor(); DynamicObject* pParentMetadata = (pParentDesc == NULL) ? NULL : pParentDesc->getMetadata(); for (int i = 0; i < 50; ++i) { //each pass does replacement of $M(a) currently in the string. //do 50 passes to perform sub-expansion at most fifty times, ie. prevent infinite loop //for non-terminating recursive expansion string::size_type pos = txt.find("$"); while (pos != string::npos) { if (pos + 1 >= txt.size()) { break; } string type = txt.substr(pos+1, 1); if (type != "$") //ie. not $$, the escape sequence so continue { bool replaced = false; if (pos+4 < txt.size()) //ie. $M(a) { if (txt[pos+2] == '(') { string::size_type closeParen = txt.find(')', pos+2); if (closeParen == string::npos) { closeParen = txt.size(); } string variableName = txt.substr(pos+3, closeParen-(pos+2)-1); string replacementString; if (type == "M" || type == "S") { DataElement* pElmnt = pParent; DynamicObject* pMetadata = pParentMetadata; if (variableName.substr(0, 2) == "//") { string::size_type endNamePos = variableName.find("//", 2); if (endNamePos != string::npos) { string elementName = variableName.substr(2, endNamePos - 2); variableName = variableName.substr(endNamePos + 2); if (!variableName.empty()) { if (elementName[0] == '[' && elementName[elementName.size() - 1] == ']') { elementName = elementName.substr(1, elementName.size() - 2); std::list<GraphicObject*> objects; getLayer()->getObjects(VIEW_OBJECT, objects); for (std::list<GraphicObject*>::iterator object = objects.begin(); object != objects.end(); ++object) { GraphicObject* pObj = *object; if (pObj->getName() == elementName) { SpatialDataView* pSdv = dynamic_cast<SpatialDataView*>(pObj->getObjectView()); if (pSdv != NULL) { pElmnt = pSdv->getLayerList()->getPrimaryRasterElement(); DataDescriptor* pDesc = (pElmnt == NULL) ? NULL : pElmnt->getDataDescriptor(); pMetadata = (pDesc == NULL) ? NULL : pDesc->getMetadata(); } break; } } } else { pElmnt = Service<ModelServices>()->getElement(elementName, TypeConverter::toString<RasterElement>(), NULL); DataDescriptor* pDesc = (pElmnt == NULL) ? NULL : pElmnt->getDataDescriptor(); pMetadata = (pDesc == NULL) ? NULL : pDesc->getMetadata(); } } else { pElmnt = NULL; pMetadata = NULL; } } } bool success = false; if (type == "M" && pMetadata != NULL) { DataVariant var = pMetadata->getAttributeByPath(variableName); if (var.isValid()) { DataVariant::Status status; replacementString = var.toDisplayString(&status); success = (status == DataVariant::SUCCESS); if (mMetadataObjects.find(pMetadata) == mMetadataObjects.end()) { mMetadataObjects.insert(make_pair(pMetadata, new AttachmentPtr<DynamicObject>( pMetadata, SIGNAL_NAME(Subject, Modified), Slot(this, &TextObjectImp::invalidateTexture)))); } } } else if (type == "S" && pElmnt != NULL && variableName == "CLASSIFICATION") { Classification* pClass = pElmnt->getDataDescriptor()->getClassification(); pClass->getClassificationText(replacementString); success = true; if (mClassificationObjects.find(pClass) == mClassificationObjects.end()) { mClassificationObjects.insert(make_pair(pClass, new AttachmentPtr<Classification>( pClass, SIGNAL_NAME(Subject, Modified), Slot(this, &TextObjectImp::invalidateTexture)))); } } if (!success) { replacementString = "Error!"; } replaced = true; } if (replaced) { txt.replace(pos, closeParen-pos+1, replacementString); pos = txt.find("$", pos+replacementString.size()); } } } if (!replaced) { pos = txt.find("$", pos+1); } } else { pos = txt.find("$", pos+2); } } } string::size_type pos = txt.find("$$"); while (pos != string::npos) { txt.replace(pos, 2, "$"); pos = txt.find("$$"); } return txt; }
vector<Feature*> ShapeFile::addFeatures(GraphicElement* pGraphicElement, GraphicObject* pObject, RasterElement* pGeoref, string& message) { vector<Feature*> features; message.clear(); if (pGraphicElement == NULL) { message = "Features cannot be added because the data element is invalid!"; return features; } if (pGeoref == NULL || !pGeoref->isGeoreferenced()) { message = "No georeferencing information can be found."; return features; } // Do not allow erase or toggle objects if (pObject != NULL) { if (pObject->getDrawMode() != DRAW) { message = "The " + pObject->getName() + " object is an erase or toggle object, so a feature " "will not be added."; return features; } } // Get the objects list<GraphicObject*> objects; if (pObject != NULL) { objects.push_back(pObject); } else { GraphicGroup* pGroup = pGraphicElement->getGroup(); if (pGroup != NULL) { // If the element is displayed in an annotation layer, use the selected objects AnnotationLayer* pAnnotationLayer = dynamic_cast<AnnotationLayer*>(pGroup->getLayer()); if (pAnnotationLayer != NULL) { pAnnotationLayer->getSelectedObjects(objects); } if (objects.empty()) { objects = pGroup->getObjects(); } } } // Create the features string elementName = pGraphicElement->getName(); const DynamicObject* pMetadata = getSourceMetadata(*pGraphicElement); switch (mShape) { case ShapefileTypes::POINT_SHAPE: { if (dynamic_cast<AnnotationElement*>(pGraphicElement) != NULL) { if (objects.empty()) { message = "Cannot create a shape file from an empty element."; return features; } // Get names of attributes which should be copied/exported. vector<string> attrNames; const DynamicObject* pAttributeMetadata = getSourceAttributeMetadata(*pGraphicElement); if (pAttributeMetadata != NULL) { pAttributeMetadata->getAttributeNames(attrNames); } for (list<GraphicObject*>::const_iterator it = objects.begin(); it != objects.end(); ++it) { GraphicObject* pCurrentObject = *it; if (pCurrentObject != NULL) { // Do not allow erase or toggle objects if (pCurrentObject->getDrawMode() != DRAW) { continue; } string objectName = pCurrentObject->getName(); vector<LocationType> vertices; pCurrentObject->getRotatedExtents(vertices); // Each point created from this object uses the same metadata. int idx = -1; if (pMetadata != NULL) { idx = getAttributeIndex(*pCurrentObject, *pMetadata); } LocationType pixel; for (vector<LocationType>::const_iterator verticesIter = vertices.begin(); verticesIter != vertices.end(); ++verticesIter) { // Add the feature SessionItem* pSessionItem = pGraphicElement; if (pObject != NULL) { pSessionItem = pObject; } Feature* pFeature = new Feature(pSessionItem); features.push_back(pFeature); mFeatures.push_back(pFeature); VERIFYNR(pFeature->attach(SIGNAL_NAME(Subject, Modified), Slot(this, &ShapeFile::shapeModified))); // Fields pFeature->addField("Name", string()); if (!elementName.empty()) { if (pObject != NULL) { pFeature->setFieldValue("Name", elementName + ": " + pObject->getName()); } else { pFeature->setFieldValue("Name", elementName + ": " + objectName); } } pixel.mX = verticesIter->mX + 0.5; pixel.mY = verticesIter->mY + 0.5; QString pixelName = "(" + QString::number(verticesIter->mX + 1) + ", " + QString::number(verticesIter->mY + 1) + ")"; pFeature->setFieldValue("Pixel", pixelName.toStdString()); if (idx > -1 && pAttributeMetadata != NULL) { copyMetadata(attrNames, idx, *pAttributeMetadata, *pFeature); } LocationType geo = pGeoref->convertPixelToGeocoord(*verticesIter); pFeature->addVertex(geo.mY, geo.mX); } } } } else { // The BitMaskIterator does not support negative extents and // the BitMask does not correctly handle the outside flag so // the BitMaskIterator is used for cases when the outside flag is true and // the BitMask is used for cases when the outside flag is false AoiElement* pAoiElement = dynamic_cast<AoiElement*>(pGraphicElement); VERIFYRV(pAoiElement != NULL, features); const BitMask* pMask = pAoiElement->getSelectedPoints(); if (pObject != NULL) { pMask = pObject->getPixels(); if (pMask == NULL) { message = "The " + pObject->getName() + " object cannot be represented by the " + StringUtilities::toDisplayString(mShape) + " shape type, so a feature will not be added."; return features; } } if (pMask != NULL) { BitMaskIterator maskIt(pMask, pGeoref); if ((maskIt.getCount() > 0 && pMask->isOutsideSelected() == true) || (pMask->getCount() > 0 && pMask->isOutsideSelected() == false)) { // Add features for each selected pixel int startColumn = 0; int endColumn = 0; int startRow = 0; int endRow = 0; if (pMask->isOutsideSelected() == true) { maskIt.getBoundingBox(startColumn, startRow, endColumn, endRow); } else { pMask->getBoundingBox(startColumn, startRow, endColumn, endRow); } LocationType pixel; for (int i = startColumn; i <= endColumn; i++) { for (int j = startRow; j <= endRow; j++) { if ((maskIt.getPixel(i, j) && pMask->isOutsideSelected() == true) || (pMask->getPixel(i, j) && pMask->isOutsideSelected() == false)) { // Add the feature SessionItem* pSessionItem = pGraphicElement; if (pObject != NULL) { pSessionItem = pObject; } Feature* pFeature = new Feature(pSessionItem); features.push_back(pFeature); mFeatures.push_back(pFeature); VERIFYNR(pFeature->attach(SIGNAL_NAME(Subject, Modified), Slot(this, &ShapeFile::shapeModified))); pixel.mX = i + 0.5; pixel.mY = j + 0.5; // Fields pFeature->addField("Name", string()); pFeature->addField("Pixel", string()); if (!elementName.empty()) { if (pObject != NULL) { pFeature->setFieldValue("Name", elementName + ": " + pObject->getName()); } else { pFeature->setFieldValue("Name", elementName); } } QString pixelName = "(" + QString::number(i + 1) + ", " + QString::number(j + 1) + ")"; pFeature->setFieldValue("Pixel", pixelName.toStdString()); // Vertex pixel = pGeoref->convertPixelToGeocoord(pixel); pFeature->addVertex(pixel.mY, pixel.mX); // Longitude as x-coord } } } } } } } break; case ShapefileTypes::POLYLINE_SHAPE: { if (objects.empty()) { message = "Cannot create a shape file from an empty element."; return features; } // Get names of attributes which should be copied/exported. vector<string> attrNames; const DynamicObject* pAttributeMetadata = getSourceAttributeMetadata(*pGraphicElement); if (pAttributeMetadata != NULL) { pAttributeMetadata->getAttributeNames(attrNames); } for (list<GraphicObject*>::const_iterator it = objects.begin(); it != objects.end(); ++it) { GraphicObject* pCurrentObject = *it; if (pCurrentObject != NULL) { GraphicObjectType objectType = pCurrentObject->getGraphicObjectType(); if ((objectType == LINE_OBJECT) || (objectType == POLYLINE_OBJECT) || (objectType == HLINE_OBJECT) || (objectType == VLINE_OBJECT)) { // Do not allow erase or toggle objects if (pCurrentObject->getDrawMode() != DRAW) { continue; } string objectName = pCurrentObject->getName(); vector<LocationType> vertices; pCurrentObject->getRotatedExtents(vertices); if (vertices.empty() == false) { Feature* pFeature = new Feature(pCurrentObject); features.push_back(pFeature); mFeatures.push_back(pFeature); VERIFYNR(pFeature->attach(SIGNAL_NAME(Subject, Modified), Slot(this, &ShapeFile::shapeModified))); pFeature->addField("Name", string()); if (!elementName.empty()) { pFeature->setFieldValue("Name", elementName + ": " + objectName); } // Copy attributes. if ((pMetadata != NULL) && (pAttributeMetadata != NULL)) { int idx = getAttributeIndex(*pCurrentObject, *pMetadata); if (idx > -1) { copyMetadata(attrNames, idx, *pAttributeMetadata, *pFeature); } } for (vector<LocationType>::const_iterator iter = vertices.begin(); iter != vertices.end(); ++iter) { LocationType geo = pGeoref->convertPixelToGeocoord(*iter); pFeature->addVertex(geo.mY, geo.mX); } } } } } } break; case ShapefileTypes::POLYGON_SHAPE: { if (objects.empty()) { message = "Cannot create a shape file from an empty element."; return features; } // Get names of attributes which should be copied/exported. vector<string> attrNames; const DynamicObject* pAttributeMetadata = getSourceAttributeMetadata(*pGraphicElement); if (pAttributeMetadata != NULL) { pAttributeMetadata->getAttributeNames(attrNames); } for (list<GraphicObject*>::const_iterator it = objects.begin(); it != objects.end(); ++it) { GraphicObject* pCurrentObject = *it; if (pCurrentObject != NULL) { GraphicObjectType objectType = pCurrentObject->getGraphicObjectType(); if ((objectType == RECTANGLE_OBJECT) || (objectType == ROUNDEDRECTANGLE_OBJECT) || (objectType == ELLIPSE_OBJECT) || (objectType == TRIANGLE_OBJECT) || (objectType == POLYGON_OBJECT) || (objectType == ARC_OBJECT)) { // Do not allow erase or toggle objects if (pCurrentObject->getDrawMode() != DRAW) { continue; } string objectName = pCurrentObject->getName(); vector<LocationType> vertices; pCurrentObject->getRotatedExtents(vertices); if (vertices.empty() == false) { // To represent non-polygon objects as polygons, add the first vertex as the last vertex if (objectType != POLYGON_OBJECT) { vertices.push_back(vertices.front()); } Feature* pFeature = new Feature(pCurrentObject); features.push_back(pFeature); mFeatures.push_back(pFeature); VERIFYNR(pFeature->attach(SIGNAL_NAME(Subject, Modified), Slot(this, &ShapeFile::shapeModified))); pFeature->addField("Name", string()); if (!elementName.empty()) { pFeature->setFieldValue("Name", elementName + ": " + objectName); } // Copy attributes. if ((pMetadata != NULL) && (pAttributeMetadata != NULL)) { int idx = getAttributeIndex(*pCurrentObject, *pMetadata); if (idx > -1) { copyMetadata(attrNames, idx, *pAttributeMetadata, *pFeature); } } for (vector<LocationType>::const_iterator iter = vertices.begin(); iter != vertices.end(); ++iter) { LocationType geo = pGeoref->convertPixelToGeocoord(*iter); pFeature->addVertex(geo.mY, geo.mX); } } } } } } break; case ShapefileTypes::MULTIPOINT_SHAPE: { if (dynamic_cast<AnnotationElement*>(pGraphicElement) != NULL) { if (objects.empty()) { message = "Cannot create a shape file from an empty element."; return features; } // Get names of attributes which should be copied/exported. vector<string> attrNames; const DynamicObject* pAttributeMetadata = getSourceAttributeMetadata(*pGraphicElement); if (pAttributeMetadata != NULL) { pAttributeMetadata->getAttributeNames(attrNames); } for (list<GraphicObject*>::const_iterator it = objects.begin(); it != objects.end(); ++it) { GraphicObject* pCurrentObject = *it; if (pCurrentObject != NULL) { // Do not allow erase or toggle objects if (pCurrentObject->getDrawMode() != DRAW) { continue; } Feature* pFeature = new Feature(pGraphicElement); features.push_back(pFeature); mFeatures.push_back(pFeature); VERIFYNR(pFeature->attach(SIGNAL_NAME(Subject, Modified), Slot(this, &ShapeFile::shapeModified))); // Fields pFeature->addField("Name", string()); if (!elementName.empty()) { if (pObject != NULL) { pFeature->setFieldValue("Name", elementName + ": " + pObject->getName()); } else { pFeature->setFieldValue("Name", elementName); } } // Copy attributes. if ((pMetadata != NULL) && (pAttributeMetadata != NULL)) { int idx = getAttributeIndex(*pCurrentObject, *pMetadata); if (idx > -1) { copyMetadata(attrNames, idx, *pAttributeMetadata, *pFeature); } } vector<LocationType> vertices; pCurrentObject->getRotatedExtents(vertices); for (vector<LocationType>::const_iterator iter = vertices.begin(); iter != vertices.end(); ++iter) { LocationType geo = pGeoref->convertPixelToGeocoord(*iter); pFeature->addVertex(geo.mY, geo.mX); } } } } else { // The BitMaskIterator does not support negative extents and // the BitMask does not correctly handle the outside flag so // the BitMaskIterator is used for cases when the outside flag is true and // the BitMask is used for cases when the outside flag is false AoiElement* pAoiElement = dynamic_cast<AoiElement*>(pGraphicElement); VERIFYRV(pAoiElement != NULL, features); const BitMask* pMask = pAoiElement->getSelectedPoints(); if (pObject != NULL) { pMask = pObject->getPixels(); if (pMask == NULL) { message = "The " + pObject->getName() + " object cannot be represented by the " + StringUtilities::toDisplayString(mShape) + " shape type, so a feature will not be added."; return features; } } if (pMask != NULL) { BitMaskIterator maskIt(pMask, pGeoref); if ((maskIt.getCount() > 0 && pMask->isOutsideSelected() == true) || (pMask->getCount() > 0 && pMask->isOutsideSelected() == false)) { // Add the feature SessionItem* pSessionItem = pGraphicElement; if (pObject != NULL) { pSessionItem = pObject; } Feature* pFeature = new Feature(pSessionItem); features.push_back(pFeature); mFeatures.push_back(pFeature); VERIFYNR(pFeature->attach(SIGNAL_NAME(Subject, Modified), Slot(this, &ShapeFile::shapeModified))); // Fields pFeature->addField("Name", string()); if (!elementName.empty()) { if (pObject != NULL) { pFeature->setFieldValue("Name", elementName + ": " + pObject->getName()); } else { pFeature->setFieldValue("Name", elementName); } } // Vertices int startColumn = 0; int endColumn = 0; int startRow = 0; int endRow = 0; if (pMask->isOutsideSelected() == true) { maskIt.getBoundingBox(startColumn, startRow, endColumn, endRow); } else { pMask->getBoundingBox(startColumn, startRow, endColumn, endRow); } LocationType pixel; for (int i = startColumn; i <= endColumn; i++) { for (int j = startRow; j <= endRow; j++) { if ((maskIt.getPixel(i, j) && pMask->isOutsideSelected() == true) || (pMask->getPixel(i, j) && pMask->isOutsideSelected() == false)) { pixel.mX = i + 0.5; pixel.mY = j + 0.5; pixel = pGeoref->convertPixelToGeocoord(pixel); pFeature->addVertex(pixel.mY, pixel.mX); // Longitude as x-coord } } } } } } } break; default: message = "Shape type not recognized."; return features; } if (features.empty()) { message = elementName + " has no objects that can be represented with the " + StringUtilities::toDisplayString(mShape) + " shape type, so no features can be added."; } return features; }
bool App::init() { _scene = new Scene; _core = new Core; _core->initialize(); connect(_core, SIGNAL(exit()), this, SLOT(quit())); // delete later _background = new GraphicObject; _background->setSurface(_core->getSurface("background.png")); SDL_Rect backRect = {0, 0, 1500, 843}; _background->setRect(backRect); qsrand(time(NULL)); _scene->setBack(_background); connect(_core->getEH(), SIGNAL(eventMsg(SDL_Event*)), this, SLOT(event(SDL_Event*))); // creating state ------------------------------ Battle *battle = new Battle; Scene *batScene = new Scene; battle->setScene(_scene); loadUnits(battle); // gates SDL_Rect gateRect; gateRect.x = 0; gateRect.y = 0; gateRect.w = 30; gateRect.h = 30; CombinedAnimation gateAnLeft; gateAnLeft.setSurface(_core->getSurface("leftgate.png")); gateAnLeft.setFrameLines(2); gateAnLeft.setMaxFrames(7); gateAnLeft.setFrames(0, 4); gateAnLeft.setFrames(1, 7); CombinedAnimation gateAnRight; gateAnRight.setSurface(_core->getSurface("rightgate.png")); gateAnRight.setFrameLines(2); gateAnRight.setMaxFrames(7); gateAnRight.setFrames(0, 4); gateAnRight.setFrames(1, 7); gateAnRight.flipHorizontal(); DamageableItem g1(1000, Position(310, SPAWN_LINE),Size(100, 90), 9); DamageableItem g2(1000, Position(1200, SPAWN_LINE),Size(100, 90), 19); // left castle SDL_Rect wallRect = {0, 0, 297, 230}; Animation leftWallAn; leftWallAn.setSurface(_core->getSurface("castle.png")); leftWallAn.setFrames(1); leftWallAn.setRect(wallRect); leftWallAn.flipHorizontal(); AreaItem leftWallItem(147, SPAWN_LINE, 220, 195); QSharedPointer<Castle> lCastle = QSharedPointer<Castle>(new Castle(leftWallItem, g1, leftWallAn, gateAnLeft, Position(100, SPAWN_LINE), 5, 1, 1500)); battle->setLeftCastle(lCastle); // right castle Animation wallAn; wallAn.setSurface(_core->getSurface("castle.png")); wallAn.setFrames(1); wallAn.setRect(wallRect); AreaItem wallItem(1365, SPAWN_LINE, 220, 195); QSharedPointer<Castle> rCastle = QSharedPointer<Castle>(new Castle(wallItem, g2, wallAn, gateAnRight, Position(1400, SPAWN_LINE), 5, 0, 1500)); battle->setRightCastle(rCastle); // Player stats QList<SDL_Surface*> iconSurfs; iconSurfs << _core->getSurface("warrior_icon.png"); iconSurfs << _core->getSurface("ranger_icon.png"); iconSurfs << _core->getSurface("rangerwall_icon.png"); iconSurfs << _core->getSurface("knight_icon.png"); iconSurfs << _core->getSurface("evilwarrior_icon.png"); iconSurfs << _core->getSurface("evilranger_icon.png"); iconSurfs << _core->getSurface("evilrangerwall_icon.png"); iconSurfs << _core->getSurface("evilknight_icon.png"); PlayerStats *stats = new PlayerStats(iconSurfs); battle->setPlayerStats(stats); // barrier floor QSharedPointer<AreaItem> floor = QSharedPointer<AreaItem>(new AreaItem(450, SPAWN_LINE + 700, 3000, 699, 0, true, true)); battle->setFloor(floor); // win sets GraphicObject *right = new GraphicObject(); GraphicObject *left = new GraphicObject(); GraphicObject *draw = new GraphicObject(); right->setSurface(_core->getSurface("rightwin.png")); left->setSurface(_core->getSurface("leftwin.png")); draw->setSurface(_core->getSurface("draw.png")); SDL_Rect winrect = {500, 300, 500, 200}; right->setRect(winrect); left->setRect(winrect); draw->setRect(winrect); battle->setWinPics(*left, *right, *draw); // starting _core->pushState(battle); _core->startStateTimer(17); int id = _core->addTimer(); _core->getTimer(id)->start(17); connect(_core->getTimer(id), SIGNAL(timeout()), this, SLOT(draw())); //---------------------------------------------- return true; }