Esempio n. 1
0
HLFileSystemObject*	HLDirectoryFactory::Create(const char* inPath, bool inCreateParentDirectories, const void* inData, UInt32 inDataSize)
{
	//	can't make the directory if it already exists
	ThrowIf(HLFileSystem::ObjectExists(inPath), CAException(dupFNErr), "HLDirectoryFactory::Create: the directory already exists");
	
	//	normalize the path
	char theNormalizedPath[PATH_MAX];
	HLFileSystem::NormalizePath(inPath, theNormalizedPath, PATH_MAX);
	
	//	extract the directory name
	CACFString theDirectoryName(HLFileSystem::CopyNameFromPath(theNormalizedPath));
	
	//	extract the parent path
	char theParentPath[PATH_MAX];
	HLFileSystem::CopyParentPathFromPath(theNormalizedPath, theParentPath, PATH_MAX);
	
	//	make an FSRef for the parent path
	FSRef theParentFSRef;
	bool theParentExists = HLFileSystem::MakeFSRefFromPath(theParentPath, theParentFSRef);
	if(!theParentExists && inCreateParentDirectories)
	{
		//	the parent directory doesn't exist, but we're allowed to create it
		CAAutoDelete<HLFileSystemObject> theObject(Create(theParentPath, inCreateParentDirectories, NULL, 0));
		theObject->GetFSRef(theParentFSRef);
	}
	else if(!theParentExists)
	{
		//	don't have an FSRef for the parent, so we have to bail
		DebugMessage("HLFileSystemObject::CreateDirectory: couldn't make an FSRef for the parent");
		throw CAException(fnfErr);
	}
	
	//	we have the parent FSRef and the CFString name, so create the directory
	return Create(theParentFSRef, theDirectoryName.GetCFString(), inData, inDataSize);
}
Esempio n. 2
0
//============================================================================
//		NCFArray::SetObject : Set the object.
//----------------------------------------------------------------------------
bool NCFArray::SetObject(CFArrayRef cfObject, bool takeOwnership)
{	NCFObject		theObject(cfObject, takeOwnership);
	CFIndex			n, numItems;
	NVariant		theValue;
	bool			isValid;



	// Get the state we need
	isValid = (cfObject != NULL);
	Clear();



	// Set the object
	if (isValid)
		{
		numItems = CFArrayGetCount(cfObject);
		for (n = 0; n < numItems; n++)
			{
			theValue = NMacTarget::ConvertCFToObject(CFArrayGetValueAtIndex(cfObject, n));
			AppendValue(theValue);
			}
		}

	return(isValid);
}
Esempio n. 3
0
//============================================================================
//		NCFNumber::SetObject : Set the object.
//----------------------------------------------------------------------------
bool NCFNumber::SetObject(CFNumberRef cfObject, bool takeOwnership)
{	NCFObject		theObject(cfObject, takeOwnership);
	float64_t		valueFloat64;
	float32_t		valueFloat32;
	int64_t			valueInt64;
	bool			isValid;



	// Get the state we need
	isValid = (cfObject != NULL);
	SetInt8(0);



	// Set the object
	if (isValid)
		{
		if (CFNumberGetValue(     cfObject, kCFNumberLongLongType, &valueInt64))
			SetInt64(valueInt64);
		
		else if (CFNumberGetValue(cfObject, kCFNumberFloatType,    &valueFloat32))
			SetFloat32(valueFloat32);
		
		else if (CFNumberGetValue(cfObject, kCFNumberDoubleType,   &valueFloat64))
			SetFloat64(valueFloat64);

		else
			NN_LOG("Unable to convert CFNumber to NNumber");
		}

	return(isValid);
}
Esempio n. 4
0
//============================================================================
//		NCFDictionary::SetObject : Set the object.
//----------------------------------------------------------------------------
bool NCFDictionary::SetObject(CFDictionaryRef cfObject, bool takeOwnership)
{	NCFObject		theObject(cfObject, takeOwnership);
	bool			isValid;



	// Get the state we need
	isValid = (cfObject != NULL);
	Clear();



	// Set the object
	if (isValid)
		CFDictionaryApplyFunction(cfObject, InsertValue, this);

	return(isValid);
}
Esempio n. 5
0
/*!
	@function	BoxV2ToObject
	
	@abstract	Attempt to convert a VRML 2 Box node to a Quesa object.
	
	@param		ioNode		Node to convert.
	
	@result		An object reference, or NULL on failure.
*/
CQ3ObjectRef	BoxV2ToObject( PolyValue& ioNode )
{
	TQ3Vector3D		sizes = {
		2.0f, 2.0f, 2.0f
	};
	
	PolyValue::Dictionary&	theDict( ioNode.GetDictionary() );

	if (IsKeyPresent( theDict, "size" ))
	{
		PolyValue&	sizeField( theDict["size"] );
		
		if ( (sizeField.GetType() == PolyValue::kDataTypeArrayOfFloat) or
			(sizeField.GetType() == PolyValue::kDataTypeArrayOfInt) )
		{
			PolyValue::FloatVec&	theFloats( sizeField.GetFloatVec() );
			if (theFloats.size() == 3)
			{
				sizes.x = theFloats[0];
				sizes.y = theFloats[1];
				sizes.z = theFloats[2];
			}
		}
	}
	
	TQ3BoxData boxData = {
		{ -sizes.x/2, -sizes.y/2, -sizes.z/2 },
		{ 0.0f, sizes.y, 0.0f },
		{ 0.0f, 0.0f, sizes.z },
		{ sizes.x, 0.0f, 0.0f },
		NULL, NULL
	};
	
	CQ3ObjectRef	theObject( Q3Box_New( &boxData ) );
	
	return theObject;
}
Esempio n. 6
0
//============================================================================
//		NCGImage::SetObject : Set the object.
//----------------------------------------------------------------------------
bool NCGImage::SetObject(CGImageRef cfObject, bool takeOwnership)
{	size_t				theWidth, theHeight, bitsPerPixel, bitsPerComponent;
	NCFObject			theObject(cfObject, takeOwnership);
	NCFObject			cgColorSpace, cgContext;
	CGBitmapInfo		bitmapInfo;
	NImageFormat		theFormat;
	NImage				theImage;
	bool				isValid;



	// Get the state we need
	theWidth         = CGImageGetWidth(           cfObject);
	theHeight        = CGImageGetHeight(          cfObject);
	bitsPerPixel     = CGImageGetBitsPerPixel(    cfObject);
	bitsPerComponent = CGImageGetBitsPerComponent(cfObject);



	// Select the image format
	if (bitsPerPixel == 8 && bitsPerComponent == 8)
		{
		// Convert indexed images to 32bpp without alpha
		theFormat    = kNImageFormat_RGBX_8888;
		bitmapInfo   = kCGBitmapByteOrder32Big | kCGImageAlphaNoneSkipLast;
		cgColorSpace = NCGColor::GetDeviceRGB();
		}

	else if (bitsPerPixel == 24 && bitsPerComponent == 8)
		{
		// Convert 24bpp images to 32bpp without alpha
		theFormat    = kNImageFormat_RGBX_8888;
		bitmapInfo   = kCGBitmapByteOrder32Big | kCGImageAlphaNoneSkipLast;
		cgColorSpace = NCGColor::GetDeviceRGB();
		}

	else if (bitsPerPixel == 32 && bitsPerComponent == 8)
		{
		// Convert 32bpp images to 32bpp with alpha
		theFormat    = kNImageFormat_RGBA_8888;
		bitmapInfo   = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast;
		cgColorSpace = NCGColor::GetDeviceRGB();
		}

	else
		{
		NN_LOG("Unknown image format: %d/%d", bitsPerPixel, bitsPerComponent);
		theFormat  = kNImageFormatNone;
		bitmapInfo = kCGImageAlphaNone;
		}

	if (!cgColorSpace.IsValid())
		return(false);



	// Set the object
	theImage = NImage(NSize(theWidth, theHeight), theFormat);
	isValid  = cgContext.SetObject(CGBitmapContextCreate(	theImage.GetPixels(),
															theWidth,
															theHeight,
															bitsPerComponent,
															theImage.GetBytesPerRow(),
															cgColorSpace,
															bitmapInfo));

	if (isValid)
		{
		CGContextDrawImage(cgContext, ToCG(theImage.GetBounds()), cfObject);
		*this = theImage;
		}

	return(isValid);
}
Esempio n. 7
0
/*!
	@function	IndexedLineSetV1ToObject
	
	@abstract	Attempt to convert a VRML 1 IndexedLineSet node to a Quesa object.
	
	@param		ioNode			Node to convert.
	@param		inReader		The reader object.
	
	@result		An object reference, or NULL on failure.
*/
CQ3ObjectRef	IndexedLineSetV1ToObject( PolyValue& ioNode, CVRMLReader& inReader )
{
	CQ3ObjectRef	theObject( Q3DisplayGroup_New() );
	ThrowIfNullQuesaOb_( theObject );
	PolyValue::Dictionary&	theDict( ioNode.GetDictionary() );
	int	polylineNum = 0;
	
	// I am not going to bother with normals, so it is better not to use lighting.
	CQ3ObjectRef	theShader( Q3NULLIllumination_New() );
	ThrowIfNullQuesaOb_( theShader );
	Q3Group_AddObject( theObject.get(), theShader.get() );
	
	// Gather data
	PolyValue::IntVec		pointIndices;
	PolyValue::IntVec		colorIndices;
	GetIntVecFromField( theDict, "coordIndex", pointIndices );
	GetIntVecFromField( theDict, "materialIndex", colorIndices );
	StandardizeIndexVector( pointIndices );
	StandardizeIndexVector( colorIndices );
	const SVRML1State&	theState( inReader.GetVRML1State() );
	const std::vector<TQ3Point3D>&	thePoints( theState.coordinate3 );
	const std::vector<TQ3ColorRGB>&	theColors( theState.diffuseColor );
	bool isColorPerVertex( (theState.materialBinding == eVRML1Value_PER_VERTEX) or
		(theState.materialBinding == eVRML1Value_PER_VERTEX_INDEXED) );
	// Note: the VRML 1 spec, unlike the VRML 2 spec, indicates that colors
	// can be per segment rather than per polyline.  Currently I will not
	// support that.
	bool isColorPerPolyline( (theState.materialBinding == eVRML1Value_PER_PART) or
		(theState.materialBinding == eVRML1Value_PER_PART_INDEXED) or
		(theState.materialBinding == eVRML1Value_PER_FACE) or
		(theState.materialBinding == eVRML1Value_PER_FACE_INDEXED) );
	

	// Start building polylines
	std::vector<TQ3Vertex3D>	vertices;
	std::vector<CQ3ObjectRef>	vertAttSets;
	
	for (unsigned int i = 0; i < pointIndices.size(); ++i)
	{
		if (pointIndices[i] < 0)
		{
			// FInish a PolyLine
			TQ3PolyLineData	polyData;
			polyData.numVertices = vertices.size();
			polyData.vertices = &vertices[0];
			polyData.segmentAttributeSet = NULL;
			CQ3ObjectRef	polyAtts;
			if (not theColors.empty())
			{
				polyAtts = GetIndexedMaterial( inReader, 0 );
				
				if (isColorPerPolyline)
				{
					TQ3ColorRGB	polyColor;
					if (colorIndices.empty())
					{
						polyColor = theColors[ polylineNum ];
					}
					else
					{
						polyColor = theColors[ colorIndices[polylineNum] ];
					}
					Q3AttributeSet_Add( polyAtts.get(), kQ3AttributeTypeDiffuseColor,
						&polyColor );
				}

				polyData.polyLineAttributeSet = polyAtts.get();
			}
			else
			{
				polyData.polyLineAttributeSet = NULL;
			}
			CQ3ObjectRef	polyLine( Q3PolyLine_New( &polyData ) );
			ThrowIfNullQuesaOb_( polyLine );
			Q3Group_AddObject( theObject.get(), polyLine.get() );
			vertices.clear();
			vertAttSets.clear();
			polylineNum += 1;
		}
		else
		{
			TQ3Vertex3D	aVertex;
			aVertex.point = thePoints[ pointIndices[i] ];
			if (isColorPerVertex and (not theColors.empty()))
			{
				TQ3ColorRGB	vertColor;
				if (colorIndices.empty())
				{
					vertColor = theColors[ pointIndices[i] ];
				}
				else
				{
					vertColor = theColors[ colorIndices[i] ];
				}
				CQ3ObjectRef	vertAtts( Q3AttributeSet_New() );
				ThrowIfNullQuesaOb_( vertAtts );
				Q3AttributeSet_Add( vertAtts.get(), kQ3AttributeTypeDiffuseColor,
					&vertColor );
				vertAttSets.push_back( vertAtts );
				aVertex.attributeSet = vertAtts.get();
			}
			else
			{
				aVertex.attributeSet = NULL;
			}
			vertices.push_back( aVertex );
		}
	}

	if (polylineNum == 0)
	{
		// no sense returning an empty display group
		theObject = CQ3ObjectRef();
	}
	
	return theObject;
}
Esempio n. 8
0
/*!
	@function	IndexedLineSetV2ToObject
	
	@abstract	Attempt to convert a VRML 2 IndexedLineSet node to a Quesa object.
	
	@param		ioNode			Node to convert.
	@param		inReader		The reader object.
	
	@result		An object reference, or NULL on failure.
*/
CQ3ObjectRef	IndexedLineSetV2ToObject( PolyValue& ioNode )
{
	CQ3ObjectRef	theObject( Q3DisplayGroup_New() );
	ThrowIfNullQuesaOb_( theObject );
	
	// The VRML 2 spec says that lines are not lit.
	CQ3ObjectRef	theShader( Q3NULLIllumination_New() );
	ThrowIfNullQuesaOb_( theShader );
	Q3Group_AddObject( theObject.get(), theShader.get() );
	
	PolyValue::Dictionary&	theDict( ioNode.GetDictionary() );
	
	// Gather data from fields
	std::vector<TQ3Point3D>	thePoints;
	std::vector<TQ3ColorRGB>	theColors;
	PolyValue::IntVec		pointIndices;
	PolyValue::IntVec		colorIndices;
	
	GetNodeArray( theDict, "coord", "Coordinate", "point", thePoints );
	GetNodeArray( theDict, "color", "Color", "color", theColors );
	
	GetIntVecFromField( theDict, "coordIndex", pointIndices );
	GetIntVecFromField( theDict, "colorIndex", colorIndices );
	StandardizeIndexVector( pointIndices );
	StandardizeIndexVector( colorIndices );
	
	bool	isColorPerVertex = true;
	if (IsKeyPresent( theDict, "colorPerVertex" ))
	{
		PolyValue&	theNode( theDict[ "colorPerVertex" ] );
		if (theNode.GetType() == PolyValue::kDataTypeBool)
		{
			isColorPerVertex = theNode.GetBool();
		}
	}
	
	// Start building polylines
	std::vector<TQ3Vertex3D>	vertices;
	std::vector<CQ3ObjectRef>	vertAttSets;
	int	polylineNum = 0;
	
	for (unsigned int i = 0; i < pointIndices.size(); ++i)
	{
		if (pointIndices[i] < 0)
		{
			// FInish a PolyLine
			TQ3PolyLineData	polyData;
			polyData.numVertices = vertices.size();
			polyData.vertices = &vertices[0];
			polyData.segmentAttributeSet = NULL;
			CQ3ObjectRef	polyAtts;
			if ((not isColorPerVertex) and (not theColors.empty()))
			{
				TQ3ColorRGB	polyColor;
				if (colorIndices.empty())
				{
					polyColor = theColors[ polylineNum ];
				}
				else
				{
					polyColor = theColors[ colorIndices[polylineNum] ];
				}
				polyAtts = CQ3ObjectRef( Q3AttributeSet_New() );
				ThrowIfNullQuesaOb_( polyAtts );
				Q3AttributeSet_Add( polyAtts.get(), kQ3AttributeTypeDiffuseColor,
					&polyColor );
				polyData.polyLineAttributeSet = polyAtts.get();
			}
			else
			{
				polyData.polyLineAttributeSet = NULL;
			}
			CQ3ObjectRef	polyLine( Q3PolyLine_New( &polyData ) );
			ThrowIfNullQuesaOb_( polyLine );
			Q3Group_AddObject( theObject.get(), polyLine.get() );
			vertices.clear();
			vertAttSets.clear();
			polylineNum += 1;
		}
		else
		{
			TQ3Vertex3D	aVertex;
			aVertex.point = thePoints[ pointIndices[i] ];
			if (isColorPerVertex and (not theColors.empty()))
			{
				TQ3ColorRGB	vertColor;
				if (colorIndices.empty())
				{
					vertColor = theColors[ pointIndices[i] ];
				}
				else
				{
					vertColor = theColors[ colorIndices[i] ];
				}
				CQ3ObjectRef	vertAtts( Q3AttributeSet_New() );
				ThrowIfNullQuesaOb_( vertAtts );
				Q3AttributeSet_Add( vertAtts.get(), kQ3AttributeTypeDiffuseColor,
					&vertColor );
				vertAttSets.push_back( vertAtts );
				aVertex.attributeSet = vertAtts.get();
			}
			else
			{
				aVertex.attributeSet = NULL;
			}
			vertices.push_back( aVertex );
		}
	}
	
	if (polylineNum == 0)
	{
		// no sense returning an empty display group
		theObject = CQ3ObjectRef();
	}
	
	
	return theObject;
}