BOOL CDialogDefaultAttribList::GetDefaultAttrib(CControlUI* pControl, CString& strValue)
{
	TiXmlElement xmlElement("DefaultAtrib");
	CLayoutManager::SaveProperties(pControl, &xmlElement, FALSE);

	TiXmlNode* pNode;
	TiXmlAttribute* pAttrib;
	pNode = xmlElement.FirstChild();
	if(pNode->Type() != TiXmlNode::ELEMENT)
	{
		return FALSE;
	}

	CStringA strValueA;
	CStringA strA;
	pAttrib = pNode->ToElement()->FirstAttribute();
	while(pAttrib)
	{
		const char* pstrName = pAttrib->Name();
		if(strcmp(pstrName, "name") != 0 && strcmp(pstrName, "pos") != 0)
		{
			strA.Format("%s=\"%s\" ", pstrName, pAttrib->Value());
			strValueA += strA;
		}
		pAttrib = pAttrib->Next();
	}

	strValue = StringConvertor::Utf8ToWide(strValueA);
	return TRUE;
}
Example #2
0
 void Parser::xmlElementContent(XmlContext* ctx)
 {
     for (;;) {
         xmlAtom();
         switch (T0) {
             case T_XmlProcessingInstruction:
             case T_XmlComment:
             case T_XmlCDATA:
             case T_XmlName:
             case T_XmlWhitespace:
             case T_XmlText:
             case T_XmlString:
             case T_XmlRightBrace:
             case T_XmlRightAngle:
             case T_XmlSlashRightAngle:
             case T_XmlEquals:
                 xmlAssert(ctx, T0);
                 continue;
             case T_XmlLeftBrace:
                 xmlExpression(ctx, ESC_elementValue);
                 continue;
             case T_XmlLeftAngle:
                 xmlAssert(ctx, T0);
                 xmlAtomSkipSpace();
                 xmlElement(ctx);
                 continue;
             case T_XmlLeftAngleSlash:
                 return;
             default:
                 compiler->internalError(position(), "Unexpected state in XML parsing");
         }
     }
 }
Expr* Parser::xmlInitializer()
{
    AvmAssert( (T0 == T_BreakXml || T0 == T_LessThan) && T1 == T_LAST );

    XmlContext ctx(compiler);
    bool is_list = false;
    uint32_t pos = position();

    if (T0 == T_LessThan)
        xmlPushback('<');
    xmlAtom();
    switch (T0) {
    case T_XmlComment:
    case T_XmlCDATA:
    case T_XmlProcessingInstruction:
        xmlAssert(&ctx, T0);
        break;

    case T_XmlLeftAngle:
        xmlAssert(&ctx, T0);
        xmlAtomSkipSpace();
        if (T0 == T_XmlRightAngle) {
            is_list = true;
            xmlListInitializer(&ctx);
        }
        else
            xmlElement(&ctx);
        break;

    default:
        compiler->internalError(position(), "error state in xml handling");
        /*NOTREACHED*/
        break;
    }

    next();				// Re-synchronize the lexer for normal lexing
    return ALLOC(XmlInitializer, (ctx.get(), is_list, pos));
}
void MyPlugin2SelectionObserver::HandleSelectionChanged(const ISelectionMessage* selectionMessage)
{
	// get selection manager for active selection.
	ISelectionManager* iSelectionManager = Utils<ISelectionUtils>()->GetActiveSelection();
	return;
	//get pointer to textSelectionSuite using selection manager OR fCurrentSelection.
	InterfacePtr<ITextSelectionSuite> iTextSelectionSuite(iSelectionManager, UseDefaultIID());
	CAlert::InformationAlert("Selection** changed..");
	if (iTextSelectionSuite) {
		//get pointer to integrator target text using textSelectionSuite.
		//Use to  Return a list of interfaces from the "concrete selection"
		InterfacePtr<const IIntegratorTarget> iIntegratorTarget_text(iTextSelectionSuite, UseDefaultIID());
		if (iIntegratorTarget_text == nil)
			return;
		RangeData rangeData(0, RangeData::kLeanForward);
		UIDRef textRef;
		PMString tagName;
		PMString childCountString = "xml child count-";
		PMString tagUIDString = "UID of TAG -";
		UID tagUID;
		TextIndex startPosXML = 0, endPosXML = 0;
		int startIndexSelection;
		int endIndexSelection;
		// Return a list of interfaces from the "concrete selection"
		//auto_ptr automatically makes clean up of objects.
		std::auto_ptr<IIntegratorTarget::TargetSuiteCollection> selectionSuites_text(iIntegratorTarget_text->GetTarget(ITextTarget::kDefaultIID));
		for (IIntegratorTarget::TargetSuiteCollection::size_type i = 0; i < selectionSuites_text->size(); i++)
		{
			//Get target text.
			ITextTarget* target = (ITextTarget*)selectionSuites_text->at(i).get();
			if (!target)
				continue;
			// extract range from target text.
			rangeData = target->GetRange();
			
			// get start and end index of range selected.
			 startIndexSelection = rangeData.Start(nil);
			 endIndexSelection = rangeData.End();
		

			// get text model for target text.
			InterfacePtr<ITextModel>textModel(target->QueryTextModel());
			
			// get UIDRef of text model.
			textRef	= target->GetTextModel();

			// query xml reference data for text model.
			IXMLReferenceData *xmlReferenceData = Utils<IXMLUtils>()->QueryXMLReferenceData(textRef);
			if (xmlReferenceData)
			{
				// get xml reference from xml reference data.
				XMLReference xmlRef = xmlReferenceData->GetReference();
			
				// obtain xml element from xml reference
				InterfacePtr<IIDXMLElement> xmlElement(xmlRef.Instantiate());
				if (xmlElement != nil) {
					childCountString.AppendNumber(xmlElement->GetChildCount());
					XMLReference childRef = xmlElement->GetNthChild(0);
					InterfacePtr<IIDXMLElement> childXMLElement(childRef.Instantiate());
					if (childXMLElement != nil){
						tagUID = childXMLElement->GetTagUID();
						tagName = childXMLElement->GetTagString();
						Utils<IXMLUtils>()->GetElementMarkerPositions(childXMLElement, &startPosXML, &endPosXML);
					}
		    	}

			}
							
		} // for end
		int length = rangeData.Length();
		if (length >= 1) {
			PMString textFrameContentLength = "selected content length-";
			textFrameContentLength.AppendNumber(length);
			PMString srtPosString = "Start Position XML tag-";
			PMString endPosString = "End postion XML tag-";
			PMString srtPosSelString = "Start Position of Selection-";
			PMString endPosSelString = "End postion Selection-";
			srtPosString.AppendNumber(startPosXML);
			endPosString.AppendNumber(endPosXML);
			srtPosSelString.AppendNumber(startIndexSelection);
			endPosSelString.AppendNumber(endIndexSelection);
			CAlert::InformationAlert(textFrameContentLength);
			CAlert::InformationAlert(childCountString);
			CAlert::InformationAlert(tagName);
			CAlert::InformationAlert(srtPosString);
			CAlert::InformationAlert(endPosString);
			CAlert::InformationAlert(srtPosSelString);
			CAlert::InformationAlert(endPosSelString);

			if (startPosXML <= startIndexSelection && endPosXML >= endIndexSelection) {
				CAlert::InformationAlert("Selection inside tag- "+tagName);
			}
			else
			{
				CAlert::WarningAlert("Selection not inside tag- " + tagName);
			}
		}
	}
	// --------:: Table selection ::---------
	InterfacePtr<ITableSelectionSuite> iTableSelectionSuite(fCurrentSelection, UseDefaultIID());
	if (iTableSelectionSuite == nil)
		return;

	InterfacePtr<const IIntegratorTarget> iIntegratorTarget_table(iTableSelectionSuite, UseDefaultIID());
	if (iIntegratorTarget_table == nil)
		return;

	UIDRef 	tableUIDRef;
	GridArea tableGridArea;
	PMString PMRowCount = "Total no of rows-";
	PMString PMColCount = "Total no of cols-";
	std::auto_ptr<IIntegratorTarget::TargetSuiteCollection> selectionSuites_table(iIntegratorTarget_table->GetTarget(ITableTarget::kDefaultIID));
	for (IIntegratorTarget::TargetSuiteCollection::size_type i = 0; i < selectionSuites_table->size(); i++)
	{
		ITableTarget* target = (ITableTarget*)selectionSuites_table->at(i).get();
		if (!target)
			continue;
		tableUIDRef = target->GetModel();
		if (tableUIDRef != UIDRef(nil, kInvalidUID))
		{
			CAlert::WarningAlert("Table selection occured");
			tableGridArea = target->GetRange();
		}
		InterfacePtr<ITableModel>tableModel(target->QueryModel());
		if (tableModel != nil) {
			RowRange totalRows = tableModel->GetTotalRows();
			ColRange totalCols = tableModel->GetTotalCols();
			int rowCount = totalRows.count;
			int colCount = totalCols.count;
			PMRowCount.AppendNumber(rowCount);
			PMColCount.AppendNumber(colCount);
			CAlert::InformationAlert(PMRowCount);
			CAlert::InformationAlert(PMColCount);

			InterfacePtr<ITableLayout> tableLayout(tableModel, UseDefaultIID());
			if (tableLayout == nil) {
				break;
			}
			CAlert::InformationAlert("table layout present");
			ITableLayout::frame_iterator frameIter = tableLayout->begin_frame_iterator();
			CAlert::InformationAlert("Frame Iterator ppresent");
			
			CAlert::InformationAlert("Frame Iterator present");
			
			InterfacePtr<ITableFrame> tableFrame(frameIter->QueryFrame());
			CAlert::InformationAlert("table frame ppresent");
			if (tableFrame == nil){
				break;
			}
			CAlert::InformationAlert("table frame present");
			UIDRef tableContainerUIDRef = tableFrame->GetFrameRef();
			if (tableContainerUIDRef == nil){
				break;
			}
			CAlert::InformationAlert("table container UIDRef present");
			InterfacePtr<IFrameType> frameType(tableContainerUIDRef, UseDefaultIID());
			//if (frameType == nil) {
				//break;
			//}
			CAlert::InformationAlert("container frame present");
			PMString textFrameType = "Is container , text frame-";   // TYPE OF TEXT FRAME
			
		//	bool isTextFrame = frameType->IsTextFrame();
			CAlert::InformationAlert("Is text frame success");

			if (true) {
				textFrameType.Append("YES");
				CAlert::InformationAlert(textFrameType);
			}
			else {
				textFrameType.Append("NO");
				CAlert::InformationAlert(textFrameType);
			}
		}
	}
	
};
void XmlParser::readLights(Scene * scene, XmlNode * lights) {
    if (lights) {
        // Read all lights from scene
        XmlNode * light = lights->first_node("light");
        while (light) {
            // Create light
            Light * l = new Light();

            // Get position from xml
            XmlNode * position;
            xmlElement(position, light);
            // Get coordinates
            XmlAttr * x, * y, * z;
            xmlAttribute(x, position);
            xmlAttribute(y, position);
            xmlAttribute(z, position);
            // Set position
            l->setPosition(atof(x->value()), atof(y->value()), atof(z->value()));

            // Get direction from xml
			XmlNode * direction;
			xmlElement(direction, light);
			// Get coordinates
			xmlAttribute(x, direction);
			xmlAttribute(y, direction);
			xmlAttribute(z, direction);
			// Set position
			l->setDirection(atof(x->value()), atof(y->value()), atof(z->value()));

			// Check angle
			XmlNode * angle = light->first_node("angle");
			if (angle) {
				XmlAttr * value;
				xmlAttribute(value, angle);
				l->setLightAngle(atof(value->value()));
			}

            // Try to get diffuse
            XmlNode * diffuse = light->first_node("diffuse");
            if (diffuse) {
                // Get coordinates
                XmlAttr * r, * g, * b;
                xmlAttribute(r, diffuse);
                xmlAttribute(g, diffuse);
                xmlAttribute(b, diffuse);
                // Set diffuse
                l->setDiffuse(atof(r->value()), atof(g->value()), atof(b->value()));
            }

            // Try to get specular
            XmlNode * specular = light->first_node("specular");
            if (specular) {
                // Get coordinates
                XmlAttr * r, * g, * b;
                xmlAttribute(r, specular);
                xmlAttribute(g, specular);
                xmlAttribute(b, specular);
                // Set specular
                l->setSpecular(atof(r->value()), atof(g->value()), atof(b->value()));
            }

            // Read scripts
            XmlNode * scripts = light->first_node("scripts");
            readScripts(scene, l, scripts);

            // Add to scene
            scene->addLight(l);

            // Get next light
            light = light->next_sibling("light");
        }
    } else {
        printf("No lights\n");
    }
}
void XmlParser::loadFromXml(const char * fileName, int * argc, char ** argv) {
    XmlFile xmlFile(fileName);
    XmlDocument doc;
    doc.parse<0>(xmlFile.data());
    int W, H;

    XmlNode * rtNode = doc.first_node("ge");

    /*** Read window information ***/
    XmlNode * windowNode = rtNode->first_node("window");
    if (windowNode) {
        // Try to read window name
        XmlNode * name;
        xmlElement(name, windowNode);

        // Read width and height
        XmlNode * width, *height;
        xmlElement(width, windowNode);
        xmlElement(height, windowNode);

        W = atoi(width->value());
        H = atoi(height->value());

        // Set window parameters
        GameWindow::setWindow((name) ? name->value() : "GE", W, H);
    } else {
        W = 512;
        H = 512;

        GameWindow::setWindow("GE", W, H);
    }
    // Init gamewindow and light
    GameWindow::init(argc, argv);
    Light::init();
    Material::init();
    Input::init();
    GBuffer::init(W,H);
    // Load noise texture
    glActiveTexture(GL_TEXTURE11);
    LoadTexBMP("textures/noise.bmp");
    /*** Read Scene ***/
    // Reference to scene node
    XmlNode * sceneNode = rtNode->first_node("scene");
    // Instantiate scene    
    Scene * scene = new Scene();
    // Instantiate renderer
    Renderer * renderer = new Renderer();
    // Set renderer
    GameWindow::setRenderer(renderer);
    renderer->setScene(scene);

	// Create camera
	Camera * camera = new Camera();
	// Set camera
	renderer->setCamera(camera);
	camera->setAspectRatio(W/H);

	// Read Camera
	XmlNode * cameraNode = rtNode->first_node("camera");
	if (cameraNode) {
		readModel(camera, cameraNode->first_node("model"));
//		// Set position
//		XmlNode * position = cameraNode->first_node("position");
//		if (position) {
//			// Get coordinates
//			XmlAttr * x, *y, *z;
//			xmlAttribute(x, position);
//			xmlAttribute(y, position);
//			xmlAttribute(z, position);
//			camera->setPosition(atof(x->value()), atof(y->value()), atof(z->value()));
//		}
//
//		// Set direction
//		XmlNode * direction= cameraNode->first_node("direction");
//		if (direction) {
//			// Get coordinates
//			XmlAttr * x, *y, *z;
//			xmlAttribute(x, direction);
//			xmlAttribute(y, direction);
//			xmlAttribute(z, direction);
//			camera->setDirection(atof(x->value()), atof(y->value()),
//					atof(z->value()));
//		}
//
//
//		// Set direction
//		XmlNode * up = cameraNode->first_node("up");
//		if (up) {
//			// Get coordinates
//			XmlAttr * x, *y, *z;
//			xmlAttribute(x, up);
//			xmlAttribute(y, up);
//			xmlAttribute(z, up);
//			camera->setUp(atof(x->value()), atof(y->value()),
//					atof(z->value()));
//		}

		// Read scripts
		XmlNode * scriptsNode = cameraNode->first_node("scripts");
		readScripts(scene, camera, scriptsNode);
	}

    // Light shadow map must be initialized after renderer has a camera
    Light::initShadowMap(renderer->createShaderProg("shaders/shadow.vert", "shaders/shadow.frag"));

    // Read objects
    XmlNode * objectsNode = sceneNode->first_node("objects");
    if (objectsNode) {
        // Read all cubes
        XmlNode * cubeNode = objectsNode->first_node("cube");
        readCubes(renderer, scene, cubeNode);

        // Read all mesh from scene
        XmlNode * meshNode = objectsNode->first_node("mesh");
        readMeshs(renderer, scene, meshNode);
        
    } else {
        printf("No objects\n");
    }

    // Read Lights
    XmlNode * lights = sceneNode->first_node("lights");
    readLights(scene, lights);
}