示例#1
0
//TODO: Optimize this ..
void Sprite::init(TiXmlElement * pElement)
{
    if(pElement->ValueStr() != "sprite")
        return;

    TiXmlAttribute * pAtt = pElement->FirstAttribute();
    setFPS( pAtt->IntValue() );

    TiXmlElement * pChild = pElement->FirstChildElement();
    while(pChild != NULL)
    {
        if(pChild->ValueStr() != "surface")
            continue;

        std::string fileName = pChild->GetText();
        SDL_SurfacePtr pSurface = load_image(fileName);
        float zoom = 1.0f;
        float rot = 0.0f;
        float alpha = 1.0;

        TiXmlAttribute * pAttrib = pChild->FirstAttribute();
        if(pAttrib != NULL)
        {
            SDL_Rect rect = {-1,-1,-1,-1};
            while(pAttrib != NULL)
            {
                //std::cout << pAttrib->Name() << std::endl;
                if(pAttrib->Name() == std::string("x"))
                    rect.x = pAttrib->IntValue();
                else if(pAttrib->Name() == std::string("y"))
                    rect.y = pAttrib->IntValue();
                else if(pAttrib->Name() == std::string("w"))
                    rect.w = pAttrib->IntValue();
                else if(pAttrib->Name() == std::string("h"))
                    rect.h = pAttrib->IntValue();
                else if(pAttrib->Name() == std::string("rot"))
                    rot = pAttrib->DoubleValue();
                else if(pAttrib->Name() == std::string("zoom"))
                    zoom = pAttrib->DoubleValue();
                else if(pAttrib->Name() == std::string("alpha"))
                    alpha = pAttrib->DoubleValue();

                pAttrib = pAttrib->Next();
            }
            if( rect.x != -1 && rect.y != -1 && rect.w != -1 && rect.h != -1)
                pSurface = getSurface( pSurface.get(), rect );
            if( zoom != 1.0 || rot != 0.0f )
                pSurface = rotozoomSurface( pSurface.get(), rot, zoom, 1); //1 is for smoothing
            if( alpha != 1.0 )
            {
                int a = 255*alpha;
                SDL_SetAlpha( pSurface.get(), SDL_SRCALPHA|SDL_RLEACCEL, a);
            }
        }

        m_Sprites.push_back( new SDL_SurfacePtr(pSurface) );
        pChild = pChild->NextSiblingElement();
    }
}
示例#2
0
void ImageLoader::Load(TiXmlDocument& doc)
{
	TiXmlElement* root = doc.FirstChildElement("Body");
	root = root->FirstChildElement("Image");
	while (root)
	{
		TiXmlAttribute* attribute = root->FirstAttribute();
		std::string str = attribute->Name();
		if (str == "name")
		{
			std::string imageName = attribute->Value();
			std::string fileName;
			int x1 = -1, x2 = -1, y1 = -1, y2 = -1;
			TiXmlElement* element = root->FirstChildElement("a");
			if (element)
			{
				if (element->Attribute("file"))
				{
					fileName = element->Attribute("file");
				}
			}

			element = root->FirstChildElement("rect");

			while (element)
			{

				TiXmlAttribute* attrib = element->FirstAttribute();
				while (attrib)
				{
					std::string name = attrib->Name();
					if (name == "x1")
					{
						x1 = attrib->IntValue();
					}
					else if (name == "x2")
					{
						x2 = attrib->IntValue();
					}
					else if (name == "y1")
					{
						y1 = attrib->IntValue();
					}
					else if (name == "y2")
					{
						y2 = attrib->IntValue();
					}

					attrib = attrib->Next();
				}
				element = element->NextSiblingElement("rect");
			}

			internalCreate(imageName, fileName, x1, y1, x2, y2);
		}

		root = root->NextSiblingElement("Image");
	}
}
示例#3
0
void MeshCompiler::CompileAnimations( TiXmlElement* Arm )
{
	// Get named animations from the keyframes
	for( TiXmlElement* Keyf = Arm->FirstChildElement( "anim" ); Keyf; Keyf = Keyf->NextSiblingElement( "anim" ) )
	{
		Animation Animation;

		// Get starting frame and name (patch up lengths later)
		TiXmlAttribute* KeyfAttr = Keyf->FirstAttribute();
		Animation.m_StartFrame = (uint16)KeyfAttr->IntValue();

		KeyfAttr = KeyfAttr->Next();
		const char* pName = KeyfAttr->Value();
		CleanStrncpy( Animation.m_Name, pName, ANIM_NAME_LENGTH );
		Animation.m_HashedName = Animation.m_Name;

		m_Animations.PushBack( Animation );
		++m_Header.m_NumAnims;
	}
	for( int i = 0; i < ( m_Header.m_NumAnims - 1 ); ++i )
	{
		Animation& ThisAnim = m_Animations[ i ];
		Animation& NextAnim = m_Animations[ i + 1 ];
		ThisAnim.m_Length = NextAnim.m_StartFrame - ThisAnim.m_StartFrame;
	}
	// Patch up the last animation's length separately
	if( m_Header.m_NumAnims )
	{
		Animation& ThisAnim = m_Animations[ m_Header.m_NumAnims - 1 ];
		ThisAnim.m_Length = (uint16)( ( m_Header.m_NumFrames ) - ThisAnim.m_StartFrame );	// -1 because of added T-pose
	}
}
示例#4
0
// static member function
HeeksObj* CAdaptive::ReadFromXMLElement(TiXmlElement* element)
{
	CAdaptive* new_object = new CAdaptive;

	std::list<TiXmlElement *> elements_to_remove;

	// read solid and sketch ids
	for(TiXmlElement* pElem = heeksCAD->FirstXMLChildElement( element ) ; pElem; pElem = pElem->NextSiblingElement())
	{
		std::string name(pElem->Value());
		if(name == "params"){
			new_object->m_params.ReadFromXMLElement(pElem);
			elements_to_remove.push_back(pElem);
		}
		else if(name == "solid"){
			for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next())
			{
				std::string name(a->Name());
				if(name == "id"){
					int id = a->IntValue();
					new_object->m_solids.push_back(id);
				}
			}
			elements_to_remove.push_back(pElem);
		}
		else if(name == "sketch"){
			for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next())
			{
				std::string name(a->Name());
				if(name == "id"){
					int id = a->IntValue();
					new_object->m_sketches.push_back(id);
				}
			}
			elements_to_remove.push_back(pElem);
		}
	}

	for (std::list<TiXmlElement*>::iterator itElem = elements_to_remove.begin(); itElem != elements_to_remove.end(); itElem++)
	{
		heeksCAD->RemoveXMLChild( element, *itElem);
	}

	new_object->ReadBaseXML(element);

	return new_object;
}
示例#5
0
Globals::Globals(TiXmlElement *root)
    :
    nodeCounter(-1),
    linkCounter(-1),
    speciesCounter(-1)
{
    cout << "Populating sigmoid table...";
    for (int a=0; a<6001; a++)
    {
        signedSigmoidTable[a] = ((1 / (1+exp(-((a-3000)/1000.0)))) - 0.5)*2.0;
        unsignedSigmoidTable[a] = 1 / (1+exp(-((a-3000)/1000.0)));
    }
    cout << "done!\n";

    TiXmlAttribute *firstAttribute = root->FirstAttribute();

    while (firstAttribute)
    {
        if (iequals(firstAttribute->Name(),"NodeCounter"))
        {
            nodeCounter = firstAttribute->IntValue();
        }
        else if (iequals(firstAttribute->Name(),"LinkCounter"))
        {
            linkCounter = firstAttribute->IntValue();
        }
        else if (iequals(firstAttribute->Name(),"SpeciesCounter"))
        {
            speciesCounter = firstAttribute->IntValue();
        }
        else
        {
            addParameter( firstAttribute->Name() , firstAttribute->DoubleValue());
        }

        firstAttribute = firstAttribute->Next();
    }

    if (nodeCounter==-1 || linkCounter==-1 || speciesCounter==-1)
    {
        throw CREATE_LOCATEDEXCEPTION_INFO("MALFORMED XML!");
    }

    cacheParameters();

    initRandom();
}
示例#6
0
void MeshCompiler::CompileArmature( TiXmlElement* Arm )
{
	if( Arm )
	{
		m_Header.m_HasSkeleton = true;
		TiXmlAttribute* ArmAttr = Arm->FirstAttribute();	// "frames"
		m_Header.m_NumFrames = ArmAttr->IntValue() + 1;	// + 1 for T-pose at frame 0
		for( TiXmlElement* Bone = Arm->FirstChildElement( "bonedef" ); Bone; Bone = Bone->NextSiblingElement( "bonedef" ) )
		{
			SNamedBone sbone;
			TiXmlAttribute* BoneAttr = Bone->FirstAttribute();
			const char* pName = BoneAttr->Value();
			sbone.m_Name = HashedString( pName );

			// Push an identity so frame 0 is the T-pose
			sbone.m_FrameQuats.PushBack( Quat() );
			sbone.m_FrameTransVecs.PushBack( Vector() );

			for( TiXmlElement* Frame = Bone->FirstChildElement( "frame" ); Frame; Frame = Frame->NextSiblingElement( "frame" ) )
			{
				Matrix FrameMatrix;
				TiXmlAttribute* FrameAttr = Frame->FirstAttribute();

				// In case I ever need separate frame values
				int FrameNum = FrameAttr->IntValue();
				Unused( FrameNum );

				FrameAttr = FrameAttr->Next();
				GetXMLMatrix( FrameAttr, FrameMatrix );

				Quat FrameQuat = FrameMatrix.ToQuaternion();
				Vector FrameTransVec = FrameMatrix.GetTranslationElements();

				sbone.m_FrameQuats.PushBack( FrameQuat );
				sbone.m_FrameTransVecs.PushBack( FrameTransVec );
			}

			m_Bones.PushBack( sbone );
			++m_Header.m_NumBones;
		}

		CompileAnimations( Arm );
	}
}
示例#7
0
void DataModel::loadStage()
{
    TiXmlDocument* myDocument = new TiXmlDocument();
    unsigned char* pBuffer = NULL;
    ssize_t bufferSize = 0;
    pBuffer = FileUtils::getInstance()->getFileData("stage.xml", "r", &bufferSize);
    if (pBuffer) {
        myDocument->Parse((const char*)pBuffer);
        TiXmlElement* stage = myDocument->RootElement();
        TiXmlElement* points = stage->FirstChildElement();
        TiXmlElement* point = points->FirstChildElement();
        while (points) {
            const char *name = points->Attribute("name");
            __Array *temp = __Array::create();
            
            while (point) {
                TiXmlAttribute *x = point->FirstAttribute();
                int pointX = x->IntValue();
                int pointY = x->Next()->IntValue();
                if (_winSize.height < 1100) {
                    pointY = pointY - 25;
                }
                temp->addObject(new MyPoint(pointX ,_winSize.height / 1280.0 * pointY));
                point = point->NextSiblingElement();
            }
            if (StringUtils::format("s9%d",flag9) == std::string(name)) {
                stage9.pushBack(temp);
                flag9++;
            }
            if (StringUtils::format("s5%d",flag5) == std::string(name)) {
                stage5.pushBack(temp);
                flag5++;
            }
            if (StringUtils::format("s6%d",flag6) == std::string(name)) {
                stage6.pushBack(temp);
                flag6++;
            }
            point = points->FirstChildElement();
            points = points->NextSiblingElement();
        }
        Ref *obj;
        MyPoint *p;
        for (auto a: stage5) {
            
            CCARRAY_FOREACH(a, obj)
            {
                p = (MyPoint *)obj;
            }
            
        }

    }
 
}
示例#8
0
// static member function
HeeksObj* HLine::ReadFromXMLElement(TiXmlElement* pElem)
{
	gp_Pnt p0(0, 0, 0), p1(0, 0, 0);
	HeeksColor c;

	// get the attributes
	for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next())
	{
		std::string name(a->Name());
		if(name == "col"){c = HeeksColor((long)(a->IntValue()));}
		else if(name == "sx"){p0.SetX(a->DoubleValue());}
		else if(name == "sy"){p0.SetY(a->DoubleValue());}
		else if(name == "sz"){p0.SetZ(a->DoubleValue());}
		else if(name == "ex"){p1.SetX(a->DoubleValue());}
		else if(name == "ey"){p1.SetY(a->DoubleValue());}
		else if(name == "ez"){p1.SetZ(a->DoubleValue());}
	}

	HLine* new_object = new HLine(p0, p1, &c);
	new_object->ReadBaseXML(pElem);

	if(new_object->GetNumChildren()>2)
	{
		//This is a new style line, with children points
		new_object->Remove(new_object->A);
		new_object->Remove(new_object->B);
		delete new_object->A;
		delete new_object->B;
		new_object->A = (HPoint*)new_object->GetFirstChild();
		new_object->B = (HPoint*)new_object->GetNextChild();
		new_object->A->m_draw_unselected = false;
		new_object->B->m_draw_unselected = false;
		new_object->A->SetSkipForUndo(true);
		new_object->B->SetSkipForUndo(true);
	}

	// The OpenCascade libraries throw an exception when one tries to
	// create a gp_Lin() object using a vector that doesn't point
	// anywhere.  If this is a zero-length line then we're in
	// trouble.  Don't bother with it.
	if (new_object->A == NULL || new_object->B == NULL || ((new_object->A->m_p.X() == new_object->B->m_p.X()) &&
		(new_object->A->m_p.Y() == new_object->B->m_p.Y()) &&
		(new_object->A->m_p.Z() == new_object->B->m_p.Z())))
	{
		delete new_object;
		return(NULL);
	}

	return new_object;
}
示例#9
0
//static
HeeksObj* HPoint::ReadFromXMLElement(TiXmlElement* pElem)
{
	gp_Pnt p;
	HeeksColor c;

	// get the attributes
	for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next())
	{
		std::string name(a->Name());
		if(name == "col"){c = HeeksColor((long)(a->IntValue()));}
		else if(name == "x"){p.SetX(a->DoubleValue());}
		else if(name == "y"){p.SetY(a->DoubleValue());}
		else if(name == "z"){p.SetZ(a->DoubleValue());}
	}

	HPoint* new_object = new HPoint(p, &c);
	new_object->ReadBaseXML(pElem);

	return new_object;
}
示例#10
0
void CAttachOp::WriteXML(TiXmlNode *root)
{
	TiXmlElement * element = heeksCAD->NewXMLElement( "AttachOp" );
	heeksCAD->LinkXMLEndChild( root,  element );

	element->SetDoubleAttribute( "tolerance", m_tolerance);
	element->SetDoubleAttribute( "minz", m_min_z);
	element->SetDoubleAttribute( "material_allowance", m_material_allowance);

	// write solid ids
#ifdef OP_SKETCHES_AS_CHILDREN
	for (HeeksObj *object = GetFirstChild(); object != NULL; object = GetNextChild())
	{
		if (object->GetIDGroupType() != SolidType)continue;
		int solid = object->GetID();
#else
	for (std::list<int>::iterator It = m_solids.begin(); It != m_solids.end(); It++)
    {
		int solid = *It;
#endif
		TiXmlElement * solid_element = heeksCAD->NewXMLElement( "solid" );
		heeksCAD->LinkXMLEndChild( element, solid_element );
		solid_element->SetAttribute("id", solid);
	}

	COp::WriteBaseXML(element);
}

// static member function
HeeksObj* CAttachOp::ReadFromXMLElement(TiXmlElement* element)
{
	CAttachOp* new_object = new CAttachOp;

	element->Attribute("tolerance", &new_object->m_tolerance);
	element->Attribute("minz", &new_object->m_min_z);
	element->Attribute("material_allowance", &new_object->m_material_allowance);

	std::list<TiXmlElement *> elements_to_remove;

	// read solid ids
	for(TiXmlElement* pElem = heeksCAD->FirstXMLChildElement( element ) ; pElem; pElem = pElem->NextSiblingElement())
	{
		std::string name(pElem->Value());
		if(name == "solid"){
			for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next())
			{
				std::string name(a->Name());
				if(name == "id"){
					int id = a->IntValue();
					new_object->m_solids.push_back(id);
				}
			}
			elements_to_remove.push_back(pElem);
		}
	}

	for (std::list<TiXmlElement*>::iterator itElem = elements_to_remove.begin(); itElem != elements_to_remove.end(); itElem++)
	{
		heeksCAD->RemoveXMLChild( element, *itElem);
	}

	new_object->ReadBaseXML(element);

	return new_object;
}
示例#11
0
HeeksObj* Constraint::ReadFromXMLElement(TiXmlElement* pElem)
{
	const char* type=0;
	EnumConstraintType etype=(EnumConstraintType)0;
	const char* angle=0;
	EnumAbsoluteAngle eangle=(EnumAbsoluteAngle)0;
	double length=0;
	int obj1_id=0;
	int obj2_id=0;
	int obj1_type=0;
	int obj2_type=0;
	ConstrainedObject* obj1=0;
	ConstrainedObject* obj2=0;
	// get the attributes
	for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next())
	{
		std::string name(a->Name());
		if(name == "type"){type = a->Value();}
		else if(name == "angle"){angle = a->Value();}
		else if(name == "length"){length = a->DoubleValue();}
		else if(name == "obj1_id"){obj1_id = a->IntValue();}
		else if(name == "obj1_type"){obj1_type = a->IntValue();}
		else if(name == "obj2_id"){obj2_id = a->IntValue();}
		else if(name == "obj2_type"){obj2_type = a->IntValue();}
	}

	//Ugh, we need to convert the strings back into types
	for(unsigned i=0; i < sizeof(ConstraintTypes); i++)
	{
		if(strcmp(ConstraintTypes[i].c_str(),type)==0)
		{
			etype = (EnumConstraintType)i;
			break;
		}
	}

	for(unsigned i=0; i < sizeof(AbsoluteAngle); i++)
	{
		if(strcmp(AbsoluteAngle[i].c_str(),angle)==0)
		{
			eangle = (EnumAbsoluteAngle)i;
			break;
		}
	}


	//JT
	//Ok.. There is a problem here.. Further up stream there a conditions where the xml has been written out for obj1_id, obj2_id != 0 for objects that don't exist
	//This is a huge pain, since the error is being introduced on the file save, and doesn't show up, until you load the file.
	// Sometimes you get a segmentation fault right at load... Or when you're really lucky it shows up when solvesketch kicks in and you have no clue whats going on.
    // At this point,until these critters get irridicated CheckforValidConstraint basically tries to see if the constraint makes sense
    // I hope to install this at both ends when constraints are being written out or read in my attempt to identify, isolate and irradicate these most annoying
    // critters

#ifdef CHECK_FOR_INVALID_CONSTRAINT
    bool blockConstraint =false;
    blockConstraint =  checkForInvalidConstraint(type,etype,angle,eangle,length,obj1_id,obj2_id,obj1_type,obj2_type);
    if (blockConstraint)
	{
      return NULL;
    }
#endif

	//Get real pointers to the objects
	obj1 = (ConstrainedObject*)wxGetApp().GetIDObject(obj1_type,obj1_id);
	obj2 = (ConstrainedObject*)wxGetApp().GetIDObject(obj2_type,obj2_id);

	Constraint *c = new Constraint(etype,eangle,length,obj1,obj2);

	unsigned int len;
	char *str = new char[512];
	char *cstr = str;

	printf("Searched for: 0x%X:0x%X, 0x%X:0x%X\n", obj1_type, obj1_id, obj2_type, obj2_id);
	if(obj1)
	{
		obj1->constraints.push_back(c);
		obj1->ToString(str,&len,512);
		cstr = str+len;
	}
	if(obj2)
	{
		obj2->constraints.push_back(c);
		obj2->ToString(cstr,&len,512);
		cstr = cstr+len;
	}
	printf("%s",str);

	//Don't let the xml reader try to insert us in the tree
	return NULL;
}
示例#12
0
// static
HeeksObj* HDimension::ReadFromXMLElement(TiXmlElement* pElem)
{
	double m[16];
	wxString text;
	HeeksColor c;
	double p0[3] = {0, 0, 0};
	double p1[3] = {0, 0, 0};
	double p2[3] = {0, 0, 0};
	double scale=1;

	DimensionMode mode = TwoPointsDimensionMode;
	DimensionUnits units = DimensionUnitsGlobal;

	// get the attributes
	for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next())
	{
		std::string name(a->Name());
		if(name == "col"){c = HeeksColor((long)(a->IntValue()));}
		else if(name == "m0"){m[0] = a->DoubleValue();}
		else if(name == "m1"){m[1] = a->DoubleValue();}
		else if(name == "m2"){m[2] = a->DoubleValue();}
		else if(name == "m3"){m[3] = a->DoubleValue();}
		else if(name == "m4"){m[4] = a->DoubleValue();}
		else if(name == "m5"){m[5] = a->DoubleValue();}
		else if(name == "m6"){m[6] = a->DoubleValue();}
		else if(name == "m7"){m[7] = a->DoubleValue();}
		else if(name == "m8"){m[8] = a->DoubleValue();}
		else if(name == "m9"){m[9] = a->DoubleValue();}
		else if(name == "ma"){m[10]= a->DoubleValue();}
		else if(name == "mb"){m[11]= a->DoubleValue();}
		else if(name == "scale"){scale= a->DoubleValue();}
		else if(name == "mode"){mode = (DimensionMode)(a->IntValue());}
		else if(name == "units"){
			const char* str = a->Value();
			switch(str[0])
			{
			case 'm':
				units = DimensionUnitsMM;
				break;
			case 'i':
				units = DimensionUnitsInches;
				break;
			}
		}
	}

	HDimension* new_object = new HDimension(make_matrix(m), make_point(p0), make_point(p1), make_point(p2), mode, units, &c);
	new_object->ReadBaseXML(pElem);
	new_object->m_scale = scale;

	if(new_object->GetNumChildren()>3)
	{
		//This is a new style line, with children points
		new_object->Remove(new_object->A);
		new_object->Remove(new_object->B);
		new_object->Remove(new_object->m_p2);
		delete new_object->A;
		delete new_object->B;
		delete new_object->m_p2;
		new_object->A = (HPoint*)new_object->GetFirstChild();
		new_object->B = (HPoint*)new_object->GetNextChild();
		new_object->m_p2 = (HPoint*)new_object->GetNextChild();
		new_object->A->m_draw_unselected = false;
		new_object->B->m_draw_unselected = false;
		new_object->m_p2->m_draw_unselected = false;
		new_object->A->SetSkipForUndo(true);
		new_object->B->SetSkipForUndo(true);
		new_object->m_p2->SetSkipForUndo(true);
	}


	return new_object;
}