Bool CSVNodeData::UpdateCSVTable(GvNode* node, GvRun* run, GvCalc* calc) {
    BaseDocument* doc = node->GetDocument();
    if (m_initCsv) return TRUE;

    // Obtain data to update the CSV Table. If *all* of those
    // succeeded, the CSV table is updated.
    GvPortCalc pCalc(node, &m_values, run, calc);
    Bool header;
    LONG delimiter;
    Filename filename;

    GvPort* pHeader = pCalc.GetInPort(CSVNODE_HEADER);
    if (pHeader && pHeader->GetBool(&header, run)) ;
    else return TRUE;

    GvPort* pDelimiter = pCalc.GetInPort(CSVNODE_DELIMITER);
    if (pDelimiter && pDelimiter->GetInteger(&delimiter, run)) ;
    else return TRUE;

    Bool ok = FALSE;
    GvPort* pFilename = pCalc.GetInPort(CSVNODE_FILENAME);
    filename = GvGetPortGeData(node, pFilename, run, &ok).GetFilename();
    if (!ok) return TRUE;

    // We now initialize the CSV Table and want to prevent any
    // further initialization in the calculation cycle.
    m_initCsv = TRUE;

    // Validate and set the data to the CSV Table object.
    if (m_pHeader != header) {
        m_forceUpdate = TRUE;
    }
    m_pHeader = header;
    m_table.SetHasHeader(header);

    if (delimiter < 0 || delimiter > 255) {
        delimiter = CSVNODE_DELIMITER_COMMA;
    }
    if (m_pDelimiter != delimiter) {
        m_forceUpdate = TRUE;
    }
    m_pDelimiter = delimiter;
    m_table.SetDelimiter((CHAR) delimiter);

    // Make the CSV Filename relative to the node's document if the file
    // does not exist.
    if (doc && filename.Content() && !GeFExist(filename)) {
        filename = doc->GetDocumentPath() + filename;
    }

    // Update the CSV Table.
    Bool updated = FALSE;
    Bool success = m_table.Init(filename, m_forceUpdate, &updated);
    m_forceUpdate = FALSE;

    return success;
}
Exemple #2
0
  /// Called from Message() for MSG_EDIT (when a user double-clicks
  /// the object icon). Toggles the protection state of the container.
  void ToggleProtect(BaseObject* op)
  {
    BaseDocument* doc = op->GetDocument();
    if (doc)
    {
      doc->StartUndo();
      doc->AddUndo(UNDOTYPE_CHANGE_SMALL, op);
      doc->EndUndo();
    }

    BaseContainer const* bc = op->GetDataInstance();
    if (!bc) return;

    if (!m_protected)
    {
      String password;
      if (!PasswordDialog(&password, false, true)) return;
      String hashed = HashString(password);
      m_protected = true;
      m_protectionHash = hashed;

      HideNodes(op, doc, true);
    }
    else
    {
      String password;
      Bool unlock = false;
      String emptyPassHash = HashString("");
      if (m_protectionHash == emptyPassHash)
      {
        unlock = true;
      }
      else if (PasswordDialog(&password, true, true))
      {
        unlock = (m_protectionHash == HashString(password));
        if (!unlock)
          MessageDialog(GeLoadString(IDS_PASSWORD_INVALID));
      }
      if (unlock)
      {
        m_protected = false;
        HideNodes(op, doc, false);
      }
    }

    op->Message(MSG_CHANGE);
    op->SetDirty(DIRTYFLAGS_DESCRIPTION);
    EventAdd();
  }
void SculptSelectionBrush::StartStroke(Int32 strokeCount, const BaseContainer& data)
{
	//When the user starts a brush stroke we get the currently active document and store it for later use.
	_doc = GetActiveDocument();

	//Since we are handling Undo ourselves we need to call StartUndo.
	_doc->StartUndo();

	//This tool will change the selection on a PolygonObject. Since at this point we don't know what object
	//the user is going to be using the brush on we will get all the PolygonObjects that are currently selected
	//in the scene and add an Undo for each of them.
	AutoAlloc<AtomArray> selection;
	_doc->GetActiveObjects(selection, GETACTIVEOBJECTFLAGS_0);

	Int32 a;
	for (a = 0; a < selection->GetCount(); ++a)
	{
		C4DAtom* atom = selection->GetIndex(a);

		if (atom && atom->IsInstanceOf(Opolygon))
		{
			BaseObject* pBase = (BaseObject*)atom;
			if (IsObjectEnabled(pBase))
			{
				//Because you can not create a selection of the high res sculpted object, only the base object, that
				//means the sculpting tools can not be used to create selections on an object with a Sculpt Tag.
				//Because of this plugins such as this that modify the Selection on the PolygonObject
				//should only be allowed on PolygonObjects that DO NOT have a sculpt tag.
				if (!pBase->GetTag(Tsculpt))
				{
					_doc->AddUndo(UNDOTYPE_CHANGE_SELECTION, pBase);
				}
			}
		}
	}
}
Exemple #4
0
// ------------------------------------------------------------------------------------------------
// Imports the given file into the given scene structure.
void C4DImporter::InternReadFile( const std::string& pFile,
    aiScene* pScene, IOSystem* pIOHandler)
{
    std::unique_ptr<IOStream> file( pIOHandler->Open( pFile));

    if( file.get() == NULL) {
        ThrowException("failed to open file " + pFile);
    }

    const size_t file_size = file->FileSize();

    std::vector<uint8_t> mBuffer(file_size);
    file->Read(&mBuffer[0], 1, file_size);

    Filename f;
    f.SetMemoryReadMode(&mBuffer[0], file_size);

    // open document first
    BaseDocument* doc = LoadDocument(f, SCENEFILTER_OBJECTS | SCENEFILTER_MATERIALS);
    if(doc == NULL) {
        ThrowException("failed to read document " + pFile);
    }

    pScene->mRootNode = new aiNode("<C4DRoot>");

    // first convert all materials
    ReadMaterials(doc->GetFirstMaterial());

    // process C4D scenegraph recursively
    try {
        RecurseHierarchy(doc->GetFirstObject(), pScene->mRootNode);
    }
    catch(...) {
        for(aiMesh* mesh : meshes) {
            delete mesh;
        }
        BaseDocument::Free(doc);
        throw;
    }
    BaseDocument::Free(doc);

    // copy meshes over
    pScene->mNumMeshes = static_cast<unsigned int>(meshes.size());
    pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]();
    std::copy(meshes.begin(), meshes.end(), pScene->mMeshes);

    // copy materials over, adding a default material if necessary
    unsigned int mat_count = static_cast<unsigned int>(materials.size());
    for(aiMesh* mesh : meshes) {
        ai_assert(mesh->mMaterialIndex <= mat_count);
        if(mesh->mMaterialIndex >= mat_count) {
            ++mat_count;

            ScopeGuard<aiMaterial> def_material(new aiMaterial());
            const aiString name(AI_DEFAULT_MATERIAL_NAME);
            def_material->AddProperty(&name, AI_MATKEY_NAME);

            materials.push_back(def_material.dismiss());
            break;
        }
    }

    pScene->mNumMaterials = static_cast<unsigned int>(materials.size());
    pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials]();
    std::copy(materials.begin(), materials.end(), pScene->mMaterials);
}
Bool ApplinkImporter::createObjects()
{
	BaseDocument* doc = GetActiveDocument();
	Int32 vertCnt = 0;
	const Matrix tM(Vector(0.0f, 0.0f, 0.0f), Vector(1.0f, 0.0f, 0.0f), Vector(0.0f, 1.0f, 0.0f), Vector(0.0f, 0.0f, -1.0f));

	StatusSetText("Create objects...");
	for(unsigned int i = 0; i < groups.size(); i++)
	{
		Vector *vadr = 0;// vertex adress
		CPolygon *padr = 0;// polygon adress

		Group gr = this->groups[i];

		if(this->pSet.impReplace)
		{
			BaseObject* bo = doc->SearchObject(gr.groupName);
			if(bo)
			{				
				BaseObject::Free(bo);
			}
		}

		PolygonObject* pObj = PolygonObject::Alloc(gr.numGVertices, gr.numGFaces);
		if (!pObj){ return false;}

		pObj->SetName(this->groups[i].groupName);

		//GePrint("Name group: " + pObj->GetName());
		GePrint("V count: " + String::IntToString((Int32)gr.numGVertices));
		GePrint("Poly count: " + String::IntToString((Int32)gr.numGFaces));

		vadr = pObj->GetPointW();
		padr = pObj->GetPolygonW();

		for (int p = 0; p < gr.numGFaces; p++)
		{
			padr[p] = CPolygon(gr.faces[p].vp[0] - vertCnt, gr.faces[p].vp[1] - vertCnt, gr.faces[p].vp[2] - vertCnt, gr.faces[p].vp[3] - vertCnt);
			//GePrint("poly " + LongToString(p) + ": " + LongToString(padr[p].a) + ", " + LongToString(padr[p].b) + ", " + LongToString(padr[p].c) + ", " + LongToString(padr[p].d));
		}

		for (int v = 0; v < gr.numGVertices; v++)
		{
			vadr[v] = tM * this->verticies[v + vertCnt] ;
			//GePrint("vert " + LongToString(v) + ": " + LongToString(vadr[v].x) + ", " + LongToString(vadr[v].y) + ", " + LongToString(vadr[v].z));
		}
	
//// import UV
		if(ApplinkImporter::pSet.impUV && gr.numGTVertices > 0)
		{
			UVWStruct us;
			UVWTag* uvwtag = nullptr;

			uvwtag = UVWTag::Alloc(gr.numGFaces);
			if(!uvwtag) return false;

			for (Int32 p = 0; p < gr.numGFaces; p++)
			{
				us = UVWStruct(this->uvw[gr.faces[p].vt[0]], this->uvw[gr.faces[p].vt[1]], this->uvw[gr.faces[p].vt[2]], this->uvw[gr.faces[p].vt[3]]);
				void *dataptr = uvwtag->GetDataAddressW();
				uvwtag->Set(dataptr, p, us);
			}

			pObj->InsertTag(uvwtag, NULL);
			uvwtag->Message(MSG_UPDATE);
		}

////// insert phongTag
		if (!pObj->MakeTag(Tphong)) GePrint("Error on inserting phongTag. Object: " + pObj->GetName());

/////add materials, textures and poly clusters
		if(this->pSet.impMat)
		{
			String selTagName = "";
			if(this->matArray.size() == 1)
			{
				this->InsertTextureTag(pObj, this->matArray[0].Name, selTagName);
			}
			else if(this->matArray.size() > 1)
			{
				this->InsertTextureTag(pObj, this->matArray[0].Name, selTagName);

				CPolygon ps;
				SelectionTag* polyTag = NULL;

				for (Int32 c = 1; c < this->matArray.size(); c++)
				{
					polyTag = SelectionTag::Alloc(Tpolygonselection);
					if(!polyTag) return false;

					selTagName = "Selection " + String::IntToString(c);
					polyTag->SetName(selTagName);
					BaseSelect* sel = polyTag->GetBaseSelect();
					for (Int32 p = 0; p < gr.numGFaces; p++)
					{
						if(gr.polyMatIdx[p] == c)
						{
							sel->Select(p);
						}
					}
					
					pObj->InsertTag(polyTag, this->GetLastTag(pObj));
					polyTag->Message(MSG_UPDATE);

					this->InsertTextureTag(pObj, this->matArray[c].Name, selTagName);
				}
			}
		}

		doc->InsertObject(pObj, NULL, NULL);
		pObj->Message(MSG_UPDATE);

		ModelingCommandData md;
		md.doc = doc;
		md.op  = pObj;
		if(!SendModelingCommand(MCOMMAND_REVERSENORMALS, md)) return false;

		pObj = 0;
		vertCnt += gr.numGVertices;
	}

	return true;
}
Exemple #6
0
  void UpdateGadgets(Bool relevants=false)
  {
    Int32 mode;
    Bool add_dynamics;
    GetBool(CHK_ADDDYNAMICS, add_dynamics);
    GetInt32(CMB_MODE, mode);

    BaseDocument* doc = GetActiveDocument();
    BaseObject* op = doc ? doc->GetActiveObject() : nullptr;

    Enable(EDT_MAXCONN, mode != CMB_MODE_CHAIN);
    Enable(EDT_RADIUS, mode != CMB_MODE_CHAIN);
    Enable(CHK_CLOSED, mode == CMB_MODE_CHAIN);
    Enable(CHK_COMPOUND, add_dynamics);

    // Need at least two child objects on the active object.
    Bool execEnabled = op != nullptr && op->GetDown() != nullptr
        && op->GetDown()->GetNext() != nullptr;
    Enable(BTN_EXECUTE, execEnabled);

    if (relevants)
    {
      FreeChildren(CMB_TYPE);

      Int32 pluginid;
      GetInt32(CMB_FORCE, pluginid);

      do {
        BaseObject* op = BaseObject::Alloc(pluginid);
        if (!op) break;
        AutoFree<BaseObject> free(op);

        AutoAlloc<Description> desc;
        if (!op->GetDescription(desc, DESCFLAGS_DESC_0)) break;

        BaseContainer temp;
        AutoAlloc<AtomArray> arr;
        const BaseContainer* param = desc->GetParameter(FORCE_TYPE, temp, arr);
        if (!param) break;

        const BaseContainer* cycle = param->GetContainerInstance(DESC_CYCLE);
        if (!cycle) break;

        const BaseContainer* icons = param->GetContainerInstance(DESC_CYCLEICONS);

        Int32 i = 0;
        Int32 last_id = -1;
        while (true) {
          Int32 id = cycle->GetIndexId(i++);
          if (id == NOTOK) break;

          Int32 icon = icons ? icons->GetInt32(id) : -1;

          String name = cycle->GetString(id);
          if (name.Content()) {
            if (icon > 0) name += "&i" + String::IntToString(icon);
            if (last_id < 0) last_id = id;
            AddChild(CMB_TYPE, id, name);
          }
        }

        SetInt32(CMB_TYPE, last_id);
      } while (0);

      LayoutChanged(CMB_TYPE);
    }
  }
Exemple #7
0
  Bool ExecuteAutoConnect()
  {
    ConnectOptions options;
    Bool addDynamicsTag = false, inheritDynamicsTag = true;
    GetInt32(CMB_FORCE, options.forcePluginId);
    GetInt32(CMB_TYPE, options.forceType);
    GetInt32(CMB_MODE, options.connectMode);
    GetInt32(EDT_MAXCONN, options.maxConnections);
    GetFloat(EDT_RADIUS, options.radius);
    GetBool(CHK_CLOSED, options.closedChain);
    GetBool(CHK_ADDDYNAMICS, addDynamicsTag);
    GetBool(CHK_COMPOUND, inheritDynamicsTag);

    // Create an InExcludeData for the selection object.
    GeData ge_selection(CUSTOMGUI_INEXCLUDE_LIST, DEFAULTVALUE);
    auto selectionList = static_cast<InExcludeData*>(
      ge_selection.GetCustomDataType(CUSTOMGUI_INEXCLUDE_LIST));
    if (!selectionList)
      return false;

    // Get the active document and object.
    BaseDocument* doc = GetActiveDocument();
    if (!doc)
      return false;
    BaseObject* op = doc->GetActiveObject();
    if (!op)
      return false;

    // Create the root object that will contain the connectors.
    AutoFree<BaseObject> root(BaseObject::Alloc(Onull));
    if (!root)
      return false;

    // Function to create a dynamics tag.
    auto fAddDynamicsTag = [doc] (BaseObject* op, Int32 mode)
    {
      // Create a dynamics tag for the root object if it
      // does not already exist.
      BaseTag* dyn = op->GetTag(ID_RIGIDBODY);
      if (!dyn)
      {
        dyn = op->MakeTag(ID_RIGIDBODY);
        if (dyn) doc->AddUndo(UNDOTYPE_NEW, dyn);
      }

      // Update the parameters.
      if (dyn)
      {
        dyn->SetParameter(RIGID_BODY_HIERARCHY, mode, DESCFLAGS_SET_0);
        doc->AddUndo(UNDOTYPE_CHANGE_SMALL, dyn);
      }
    };

    // This list will contain all objects that should be connected.
    // While collecting, create the dynamics tags.
    maxon::BaseArray<BaseObject*> objects;
    doc->StartUndo();
    for (BaseObject* child=op->GetDown(); child; child=child->GetNext())
    {
      objects.Append(child);
      if (addDynamicsTag && inheritDynamicsTag)
        fAddDynamicsTag(child, RIGID_BODY_HIERARCHY_COMPOUND);
    }
    if (addDynamicsTag && !inheritDynamicsTag)
      fAddDynamicsTag(op, RIGID_BODY_HIERARCHY_INHERIT);

    // If no objects where collected, quit already.
    if (objects.GetCount() <= 0)
    {
      doc->EndUndo();
      doc->DoUndo(false);
      return true;
    }

    // Create the connection objects.
    ConnectObjects(op->GetName() + ": ", objects, options);

    // Fill the selection list and insert the objects.
    for (auto it=options.output.Begin(); it != options.output.End(); ++it)
    {
      (*it)->InsertUnderLast(root);
      doc->AddUndo(UNDOTYPE_NEW, *it);
      selectionList->InsertObject(*it, 0);
    }

    root->SetName(op->GetName() + ": " + root->GetName() + " (" + options.forceName + ")");
    doc->InsertObject(root, nullptr, nullptr);
    doc->AddUndo(UNDOTYPE_NEW, root);

    // Create the selection object.
    if (selectionList->GetObjectCount() > 0)
    {
      BaseObject* selection = BaseObject::Alloc(Oselection);
      if (selection)
      {
        selection->SetParameter(SELECTIONOBJECT_LIST, ge_selection, DESCFLAGS_SET_0);
        selection->SetName(op->GetName() + ": " + options.forceName + " (" + selection->GetName() + ")");
        doc->InsertObject(selection, nullptr, nullptr);
        doc->AddUndo(UNDOTYPE_NEW, selection);
      }
      ActiveObjectManager_SetMode(ACTIVEOBJECTMODE_OBJECT, false);
      doc->SetActiveObject(selection);
    }
    else
      doc->SetActiveObject(root);

    root.Release();
    doc->EndUndo();
    EventAdd();
    return true;
  }
Exemple #8
0
BaseObject *Objectify::GetVirtualObjects(BaseObject *op, HierarchyHelp *hh)
{
    BaseDocument *doc = op->GetDocument();
    BaseContainer *data = op->GetDataInstance();
    BaseObject* obj = (BaseObject*)data->GetLink(CTT_OBJECT_LINK,doc,Obase);
    LONG crntFrame = doc->GetTime().GetFrame(doc->GetFps());
    if (!obj) return NULL;
    
    if (obj->GetType() != Ospline){
        return NULL;
    }
    // start new list
    op->NewDependenceList();
    
    // check cache for validity and check master object for changes
    Bool dirty = op->CheckCache(hh) || op->IsDirty(DIRTYFLAGS_DATA);

    // if child list has been modified
    if (!dirty) dirty = !op->CompareDependenceList();
    
    // mark child objects as processed
    op->TouchDependenceList();

    dirty = dirty || (prevFrame != crntFrame);
    prevFrame = crntFrame;
    // if no change has been detected, return original cache
    if (!dirty) return op->GetCache(hh);
    
    SplineObject* spline = (SplineObject*) obj;
    
    AutoAlloc<SplineHelp> splineHelp;
    
    StatusSetText("Collecting points");
    float positioAlongSpline = data->GetReal(POSITION_ALONG_SPLINE,0.5);
    positioAlongSpline /= 10000.0f;
    positioAlongSpline = positioAlongSpline > 1.0 ? 1.0: positioAlongSpline;
    positioAlongSpline = positioAlongSpline < 0.0 ? 0.0: positioAlongSpline;
    cout<<positioAlongSpline<<endl;
    vector<vector<float> > points;
    for (LONG i = 0; i < spline->GetSegmentCount(); i++){
        Vector p = spline->GetSplinePoint(positioAlongSpline, i);
        vector<float> point;
        point.push_back(p.x);
        point.push_back(p.y);
        point.push_back(p.z);
        points.push_back(point);
    }
    
    StatusSetText("Collected "+LongToString(points.size())+" points");

    ksearchNeighbors= data->GetLong(TRIANGULATION_MAX_NEIGHBORS, 100);
    gp3SearchRadius = data->GetReal(TRIANGULATION_MAX_SEARCH_RADIUS,30.);
    gp3MaxNeighbors = data->GetLong(KSEARCH_NEIGHBORS, 20);

    gp3Mu = data->GetReal(KSEARCH_MU, 0.5);

    vector<vector<float> > surfacePoints;
    vector<vector<int> > triIndxs;
    StatusSetBar(0);
    StatusSetText("Triangulating");
    
    bool useMls = data->GetBool(USE_MLS, false);

    tri.computeSurface(points, surfacePoints, triIndxs, ksearchNeighbors, gp3SearchRadius, gp3MaxNeighbors, gp3Mu, useMls);

    StatusSetBar(100);
    StatusSetText("Got "+LongToString(triIndxs.size())+" triangles");

    if (triIndxs.size() == 0){
        return NULL;
    }
    
    PolygonObject* myPoly = PolygonObject::Alloc(surfacePoints.size(),triIndxs.size());
    Vector* ppoints = myPoly->GetPointW();
    
    vector<float> sp;
    for (int t = 0; t < surfacePoints.size()-2; t += 3) {
        sp = surfacePoints[t];
        ppoints[t+0] = Vector(sp[0],sp[1],sp[2]);
        
        sp = surfacePoints[t+1];
        ppoints[t+1] = Vector(sp[0],sp[1],sp[2]);
        
        sp = surfacePoints[t+2];
        ppoints[t+2] = Vector(sp[0],sp[1],sp[2]);
    }
    
    for (int t = 0; t < triIndxs.size(); t ++) {
        myPoly->GetPolygonW()[t] = CPolygon(triIndxs[t][0], triIndxs[t][1], triIndxs[t][2], triIndxs[t][2]);
    }
    
    StatusClear();
    myPoly->Message(MSG_UPDATE);
    return ToPoly(myPoly);

    BaseThread* bt=hh->GetThread();
    BaseObject* main = BaseObject::Alloc(Onull);

    SplineObject* emptySpline = SplineObject::Alloc(0, SPLINETYPE_LINEAR);
    ModelingCommandData mcd;
    
    mcd.doc = doc;
    
    mcd.op = emptySpline;
    
    if(!SendModelingCommand(MCOMMAND_JOIN, mcd)){
        return NULL;
    }
Error:

    return NULL;
}
void SculptSelectionBrush::EndStroke()
{
	//At the end of the brush stroke (which happens on MouseUp) we end then undo.
	_doc->EndUndo();
	_doc = nullptr;
}