예제 #1
0
// The listxrecord() functions gets the xrecord associated with the 
// key "ASDK_XREC1" and lists out its contents by passing the resbuf 
// list to the function printList().
// 
void
listXrecord()
{
    AcDbObject *pObj;
    AcDbXrecord *pXrec;
    AcDbObjectId dictObjId;
    AcDbDictionary *pDict;

    pObj = selectObject(AcDb::kForRead);
    if (pObj == NULL) {
        return;
    }
    // Get the object ID of the object's extension dictionary.
    //
    dictObjId = pObj->extensionDictionary();
    pObj->close();

    // Open the extension dictionary and get the xrecord
    // associated with the key ASDK_XREC1.
    // 
    acdbOpenObject(pDict, dictObjId, AcDb::kForRead);
    pDict->getAt("ASDK_XREC1", (AcDbObject*&)pXrec,
        AcDb::kForRead);
    pDict->close();

    // Get the xrecord's data list and then close the xrecord.
    //
    struct resbuf *pRbList;
    pXrec->rbChain(&pRbList);
    pXrec->close();

    printList(pRbList);
    acutRelRb(pRbList);
}
예제 #2
0
void ZSelector<T>::setSelection(T obj, bool selecting)
{
    if (selecting) {
        selectObject(obj);
    } else {
        deselectObject(obj);
    }
}
예제 #3
0
void ZStackObjectSelector::setSelection(ZStackObject *obj, bool selecting)
{
  if (selecting) {
    selectObject(obj);
  } else {
    deselectObject(obj);
  }
}
void
CQAlignAnchorObject::
selectSlot(bool enabled)
{
  if (enabled)
    emit selectObject();
  else
    emit cancelSelect();
}
예제 #5
0
void KMyMoneyAccountTreeView::customContextMenuRequested(const QPoint &pos)
{
  Q_UNUSED(pos)
  QModelIndex index = model()->index(currentIndex().row(), AccountsModel::Account, currentIndex().parent());
  if (index.isValid() && (model()->flags(index) & Qt::ItemIsSelectable)) {
    QVariant data = model()->data(index, AccountsModel::AccountRole);
    if (data.isValid()) {
      if (data.canConvert<MyMoneyAccount>()) {
        emit selectObject(data.value<MyMoneyAccount>());
        emit openContextMenu(data.value<MyMoneyAccount>());
      }
      if (data.canConvert<MyMoneyInstitution>()) {
        emit selectObject(data.value<MyMoneyInstitution>());
        emit openContextMenu(data.value<MyMoneyInstitution>());
      }
    }
  }
}
CQAlignAnchor::
CQAlignAnchor(QWidget *parent) :
 QWidget(parent)
{
  QGridLayout *layout = new QGridLayout(this);
  layout->setMargin(0); layout->setSpacing(2);

  QLabel *anchorLabel = new QLabel("<small><b>Anchor</b></small>");

  layout->addWidget(anchorLabel, 0, 0, 1, 2);

  objectCombo_ = new QComboBox;

  objectCombo_->addItem("Selection");
  objectCombo_->addItem("Object");
  objectCombo_->addItem("Position");

  connect(objectCombo_, SIGNAL(activated(const QString &)),
          this, SLOT(objectSlot(const QString &)));

  layout->addWidget(objectCombo_, 1, 0);

  anchorStack_ = new QStackedWidget;

  anchorLabel_  = new QWidget;
  anchorObject_ = new CQAlignAnchorObject;
  anchorPoint_  = new CQAlignAnchorPoint;

  anchorStack_->addWidget(anchorLabel_);
  anchorStack_->addWidget(anchorObject_);
  anchorStack_->addWidget(anchorPoint_);

  layout->addWidget(anchorStack_, 1, 1);

  connect(anchorObject_, SIGNAL(selectObject()), this, SIGNAL(selectObject()));
  connect(anchorObject_, SIGNAL(cancelSelect()), this, SIGNAL(cancelSelect()));

  connect(anchorPoint_, SIGNAL(selectPoint()), this, SIGNAL(selectPosition()));
  connect(anchorPoint_, SIGNAL(cancelSelect()), this, SIGNAL(cancelSelect()));

  //-----

  updateState();
}
예제 #7
0
void GetCoordInventory()
{
	std::map<std::wstring, AcGePoint3d> m_3dPoints;
	u_int startIndex = 1;

	ads_real textHeightResult = 1;
	ads_real pointSizeResult = 0.25;	
	ACHAR stringResult[2];
	ACHAR prompt[100];
	AcDbObjectId pObj;	


	selectObject(pObj);
	if (pObj)
	{
		acedInitGet(RSG_NONULL | RSG_NOZERO | RSG_NONEG, NULL);
		acedGetReal(_T("\nIntroduceti inaltime text: "), &textHeightResult);
		acedGetReal(_T("\nIntroduceti dimensiunea punctului: "), &pointSizeResult);

		extractVertexCoords(pObj, m_3dPoints);
		if (m_3dPoints.size() > 0)
		{
			if (insertPoints(m_3dPoints, 32, pointSizeResult, textHeightResult))
			{
				acedInitGet(RSG_NONULL, _T("Y N"));
				acedGetKword(_T("\nInseram tabel de coordonate? [Yes No]:"), stringResult);
				if (wcscmp(stringResult, _T("N")))
				generateInventarTable(m_3dPoints,textHeightResult);

				//swprintf(prompt, _T("\nExportam fisier de coordonate? [Y/N]<stringResult=%s>: "), stringResult);
				acedInitGet(RSG_NONULL, _T("Y N"));
				acedGetKword(_T("\nExportam fisier de coordonate? [Yes No]: " ), stringResult);
				if (wcscmp(stringResult, _T("N")))
				{
				
				struct resbuf* result = NULL;
				if (acedGetFileNavDialog(_T("Save coordonates file"), NULL, _T("csv;txt"), _T("Save Dialog"), 1, &result) != RTERROR)
				{
					ExportClass* csvExport = new ExportClass(result->resval.rstring);
					csvExport->exportInventarCSV(m_3dPoints, startIndex);

					//*****Release memory area*****/
					acutRelRb(result);
					delete csvExport;
				}
				}
			}
		}
	}

	else
	{
		acutPrintf(_T("\nError nici un obiect selectat!"));
	}

}
예제 #8
0
// The createXrecord() functions creates an xrecord object, 
// adds data to it, and then adds the xrecord to the extension 
// dictionary of a user selected object.
// 
// THE FOLLOWING CODE APPEARS IN THE SDK DOCUMENT.
//
void
createXrecord()
{
    AcDbXrecord *pXrec = new AcDbXrecord;
    AcDbObject *pObj;
    AcDbObjectId dictObjId, xrecObjId;
    AcDbDictionary* pDict;

    pObj = selectObject(AcDb::kForWrite);
    if (pObj == NULL) {
        return;
    }

    // Try to create an extension dictionary for this
    // object.  If the extension dictionary already exists,
    // this will be a no-op.
    // 
    pObj->createExtensionDictionary();

    // Get the object ID of the extension dictionary for the
    // selected object.
    // 
    dictObjId = pObj->extensionDictionary();
    pObj->close();

    // Open the extension dictionary and add the new
    // xrecord to it.
    //
    acdbOpenObject(pDict, dictObjId, AcDb::kForWrite);
    pDict->setAt("ASDK_XREC1", pXrec, xrecObjId);
    pDict->close();

    // Create a resbuf list to add to the xrecord.
    //
    struct resbuf* head;
    ads_point testpt = {1.0, 2.0, 0.0};
    head = acutBuildList(AcDb::kDxfText,
        "This is a test Xrecord list",
        AcDb::kDxfXCoord, testpt,
        AcDb::kDxfReal, 3.14159,
        AcDb::kDxfAngle, 3.14159,
        AcDb::kDxfColor, 1,
        AcDb::kDxfInt16, 180,
        0);

    // Add the data list to the xrecord.  Notice that this
    // member function takes a reference to a resbuf NOT a
    // pointer to a resbuf, so you must dereference the
    // pointer before sending it.
    // 
    pXrec->setFromRbChain(*head);
    pXrec->close();
    acutRelRb(head);
}
예제 #9
0
bool
ControlObject_select(ControlObject* self)
{
    initialize(self);

    uint64_t currentTime = Hal_getTimeInMs();

    if (isSelected(self, currentTime))
        return false;
    else
        selectObject(self, currentTime);

    return true;
}
예제 #10
0
void KMyMoneyAccountTreeView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
  QTreeView::selectionChanged(selected, deselected);
  if (!selected.empty()) {
    QModelIndexList indexes = selected.front().indexes();
    if (!indexes.empty()) {
      QVariant data = model()->data(model()->index(indexes.front().row(), AccountsModel::Account, indexes.front().parent()), AccountsModel::AccountRole);
      if (data.isValid()) {
        if (data.canConvert<MyMoneyAccount>()) {
          emit selectObject(data.value<MyMoneyAccount>());
        }
        if (data.canConvert<MyMoneyInstitution>()) {
          emit selectObject(data.value<MyMoneyInstitution>());
        }
        // an object was successfully selected
        return;
      }
    }
  }
  // since no object was selected reset the object selection
  emit selectObject(MyMoneyAccount());
  emit selectObject(MyMoneyInstitution());
}
예제 #11
0
bool SimObjectRenderer::startDrag(int x, int y, DragType type)
{
  if(dragging)
    return true;

  // look if the user clicked on an object
  dragSelection = 0;
  if(&simObject == Simulation::simulation->scene)
  {
    Vector3<> projectedClick = projectClick(x, y);
    dragSelection = selectObject(projectedClick);

    if(dragSelection)
    {
      switch(dragPlane)
      {
        case xyPlane: dragPlaneVector = Vector3<>(0.f, 0.f, 1.f); break;
        case xzPlane: dragPlaneVector = Vector3<>(0.f, 1.f, 0.f); break;
        case yzPlane: dragPlaneVector = Vector3<>(1.f, 0.f, 0.f); break;
      }
      if(type == dragRotate || type == dragNormalObject)
        dragPlaneVector = dragSelection->pose.rotation * dragPlaneVector;
      if(!intersectRayAndPlane(cameraPos, projectedClick - cameraPos, dragSelection->pose.translation, dragPlaneVector, dragStartPos))
        dragSelection = 0;
      else
      {
        dragSelection->enablePhysics(false);
        if(dragMode == resetDynamics)
          dragSelection->resetDynamics();

        dragging = true;
        dragType = type;
        if(dragMode == adoptDynamics)
          dragStartTime = System::getTime();
        return true;
      }
    }
  }

  if(!dragSelection) // camera control
  {
    dragStartPos.x = x;
    dragStartPos.y = y;
    dragging = true;
    dragType = type;
    return true;
  }
  return false;
}
예제 #12
0
bool Bitmap::loadBitmap(LPCTSTR pszFilename)
{
    // Loads a BMP image and stores it in the Bitmap object.

    HANDLE hImage = LoadImage(GetModuleHandle(0), pszFilename, IMAGE_BITMAP, 0,
                              0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);

    if (!hImage)
        return false;

    BITMAP bitmap = {0};

    if (!GetObject(hImage, sizeof(bitmap), &bitmap))
    {
        DeleteObject(hImage);
        return false;
    }

    HDC hImageDC = CreateCompatibleDC(0);

    if (!hImageDC)
    {
        DeleteObject(hImage);
        return false;
    }

    SelectObject(hImageDC, hImage);

    int h = (bitmap.bmHeight < 0) ? -bitmap.bmHeight : bitmap.bmHeight;

    if (create(bitmap.bmWidth, h))
    {
        selectObject();

        if (!BitBlt(dc, 0, 0, width, height, hImageDC, 0, 0, SRCCOPY))
        {
            destroy();
            DeleteDC(hImageDC);
            DeleteObject(hImage);
            return false;
        }

        deselectObject();
    }

    DeleteDC(hImageDC);
    DeleteObject(hImage);
    return true;
}
예제 #13
0
파일: gravity3d.c 프로젝트: archoad/Gravity
void onMouse(int button, int state, int x, int y) {
	switch (button) {
		case GLUT_LEFT_BUTTON:
			if (state == GLUT_DOWN) {
				printf("INFO: left button, x %d, y %d\n", x, y);
				selectObject(x, winSizeH-y);
			}
			break;
		case GLUT_RIGHT_BUTTON:
			if (state == GLUT_DOWN) {
				printf("INFO: right button, x %d, y %d\n", x, y);
			}
			break;
	}
}
예제 #14
0
void KInstitutionsView::show(void)
{
  if(m_needReload) {
    loadAccounts();
    m_needReload = false;
  }

  // don't forget base class implementation
  KInstitutionsViewDecl::show();

  // if we have a selected account, let the application know about it
  KMyMoneyAccountTreeBaseItem *item = m_accountTree->selectedItem();
  if(item) {
    emit selectObject(item->itemObject());
  }
}
예제 #15
0
bool printXData()
{
	CLogger::Print(_T("*Call: printxData()"));
	AcDbObject* pObj;
	
	//------------
	// Require to select an entity
	if (!(pObj = selectObject(AcDb::kForRead))) {
		CLogger::Print(_T("*Exit: printxData() - Object have not selected."));
		return false;
	}

	//------------
	// Require to enter xData application name
	ACHAR appname[133];
	if (RTNORM != acedGetString(NULL, ACRX_T("\nEnter the desired Xdata application name: "), appname)) 
	{
		CLogger::Print(_T("*Exit: printxData() - Fail to enter the application name!"));
		return false;
	}

	//------------
	// Read the xData that contained in object.
	// If application name is existing then print out its values.
	struct resbuf* pRb;
	pRb = pObj->xData(appname);
	pObj->close();
	if (pRb) {
		acutPrintf(ACRX_T("Inform: Application name '%s' is existing - The values are: "), appname);
		printList(pRb);
		acutRelRb(pRb); // release xData after using!
	} else {
		acutPrintf(ACRX_T("\n*Exit: printxData() - Application name '%s' is not existing."), appname);
		pObj->close();
		return false;
	}

	pObj->close();
	CLogger::Print(_T("*Exit: printxData()"));
	return true;
}
// This function calls the
// selectObject() function to allow the user to pick an
// object; then it accesses the xdata of the object and
// sends the list to the printList() function that lists the
// restype and resval values.
// 
void
printXdata()
{
    // Select and open an object.
    //
    AcDbObject *pObj;
    if ((pObj = selectObject(AcDb::kForRead)) == NULL) {
        return;
    }

    // Get the application name for the xdata.
    //
    TCHAR appname[133];
    if (acedGetString(NULL,
        _T("\nEnter the desired Xdata application name: "),
        appname) != RTNORM)
    {
        return;
    }

    // Get the xdata for the application name.
    //
    struct resbuf *pRb;
    pRb = pObj->xData(appname);

    if (pRb != NULL) {

        // Print the existing xdata if any is present.
        // Notice that there is no -3 group, as there is in
        // LISP. This is ONLY the xdata, so
        // the -3 xdata-start marker isn't needed.
        // 
        printList(pRb);
        acutRelRb(pRb);

    } else {
        acutPrintf(_T("\nNo xdata for this appname"));
    }
    pObj->close();
}
예제 #17
0
void TFlyObjectEdit::selectObject( int x, int y , unsigned typeBit )
{
	//int num = scene.GetObjectNumber(TRUE, TRUE);
	//if ( num != 0 )
	//{
	//	m_selectIDVec.resize( num );
	//	num = scene.GetObjects( &m_selectIDVec[0] , TRUE , TRUE , m_selectIDVec.size() );
	//}

	m_selectIDVec.clear();
	for( int i = 0 ; i < g_editDataVec.size() ; ++i )
	{
		EditData& data = g_editDataVec[i];
		if ( data.type & typeBit )
			m_selectIDVec.push_back( data.id );
	}
	OBJECTid id = view.HitObject( 
		&m_selectIDVec[0] , m_selectIDVec.size() , 
		m_camera.Object() , x , y  );

	selectObject( id );
}
예제 #18
0
rapidjson::Value* rapidJsonWrap::selectObject(const std::string &strPath)
{
	//m_pVal = NULL;
	//m_iValCurIndex = -1;
	//m_pArrayVal = NULL;
	assert(!strPath.empty());
	if(strPath.empty()) return NULL;
	SStringArrayType vec = stringUtil::split(strPath.c_str(), ":");
	if (vec.size() == 1)
	{
		if(m_pVal)
		{
			m_pVal = findValue(vec[0]);
		}
		else
		{
			rapidjson::Document::MemberIterator iter = m_doc.FindMember(vec[0].c_str());
			if(iter == m_doc.MemberEnd()) return NULL;
			m_pVal = &iter->value;
		}
		return m_pVal;
	}
	return selectObject(vec);
}
예제 #19
0
bool Bitmap::loadDesktop()
{
    // Takes a screen capture of the current Windows desktop and stores
    // the image in the Bitmap object.

    HWND hDesktop = GetDesktopWindow();

    if (!hDesktop)
        return false;

    int desktopWidth = GetSystemMetrics(SM_CXSCREEN);
    int desktopHeight = GetSystemMetrics(SM_CYSCREEN);
    HDC hDesktopDC = GetDCEx(hDesktop, 0, DCX_CACHE | DCX_WINDOW);

    if (!hDesktopDC)
        return false;

    if (!create(desktopWidth, desktopHeight))
    {
        ReleaseDC(hDesktop, hDesktopDC);
        return false;
    }

    selectObject();

    if (!BitBlt(dc, 0, 0, width, height, hDesktopDC, 0, 0, SRCCOPY))
    {
        destroy();
        ReleaseDC(hDesktop, hDesktopDC);
        return false;
    }

    deselectObject();
    ReleaseDC(hDesktop, hDesktopDC);
    return true;
}
예제 #20
0
bool Bitmap::loadPicture(LPCTSTR pszFilename)
{
    // Loads an image using the IPicture COM interface.
    // Supported image formats: BMP, EMF, GIF, ICO, JPG, WMF, TGA.
    //
    // Based on code from MSDN Magazine, October 2001.
    // http://msdn.microsoft.com/msdnmag/issues/01/10/c/default.aspx

    // IPicture interface doesn't support TGA files.
    if (_tcsstr(pszFilename, _T(".TGA")) || _tcsstr(pszFilename, _T(".tga")))
        return loadTarga(pszFilename);

    HRESULT hr = 0;
    HANDLE hFile = 0;
    HGLOBAL hGlobal = 0;
    IStream *pIStream = 0;
    IPicture *pIPicture = 0;
    BYTE *pBuffer = 0;
    DWORD dwFileSize = 0;
    DWORD dwBytesRead = 0;
    LONG lWidth = 0;
    LONG lHeight = 0;

    if (!m_logpixelsx && !m_logpixelsy)
    {
        HDC hScreenDC = CreateCompatibleDC(GetDC(0));

        if (!hScreenDC)
            return false;

        m_logpixelsx = GetDeviceCaps(hScreenDC, LOGPIXELSX);
        m_logpixelsy = GetDeviceCaps(hScreenDC, LOGPIXELSY);
        DeleteDC(hScreenDC);
    }

    hFile = CreateFile(pszFilename, FILE_READ_DATA, FILE_SHARE_READ, 0,
                       OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

    if (hFile == INVALID_HANDLE_VALUE)
        return false;

    if (!(dwFileSize = GetFileSize(hFile, 0)))
    {
        CloseHandle(hFile);
        return false;
    }

    if (!(hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD, dwFileSize)))
    {
        CloseHandle(hFile);
        return false;
    }

    if (!(pBuffer = reinterpret_cast<BYTE*>(GlobalLock(hGlobal))))
    {
        GlobalFree(hGlobal);
        CloseHandle(hFile);
        return false;
    }

    if (!ReadFile(hFile, pBuffer, dwFileSize, &dwBytesRead, 0))
    {
        GlobalUnlock(hGlobal);
        GlobalFree(hGlobal);
        CloseHandle(hFile);
        return false;
    }

    GlobalUnlock(hGlobal);
    CloseHandle(hFile);

    if (FAILED(CreateStreamOnHGlobal(hGlobal, FALSE, &pIStream)))
    {
        GlobalFree(hGlobal);
        return false;
    }

    if (FAILED(OleLoadPicture(pIStream, 0, FALSE, IID_IPicture,
                              reinterpret_cast<LPVOID*>(&pIPicture))))
    {
        pIStream->Release();
        GlobalFree(hGlobal);
        return false;
    }

    pIStream->Release();
    GlobalFree(hGlobal);

    pIPicture->get_Width(&lWidth);
    pIPicture->get_Height(&lHeight);

    width = MulDiv(lWidth, m_logpixelsx, HIMETRIC_INCH);
    height = MulDiv(lHeight, m_logpixelsy, HIMETRIC_INCH);

    if (!create(width, height))
    {
        pIPicture->Release();
        return false;
    }

    selectObject();
    hr = pIPicture->Render(dc, 0, 0, width, height, 0, lHeight, lWidth, -lHeight, 0);
    deselectObject();

    pIPicture->Release();
    return (SUCCEEDED(hr)) ? true : false;
}
예제 #21
0
파일: control.c 프로젝트: brennane/gridpot
MmsValue*
Control_readAccessControlObject(MmsMapping* self, MmsDomain* domain, char* variableIdOrig,
        MmsServerConnection connection)
{
    MmsValue* value = NULL;

    if (DEBUG_IED_SERVER)
        printf("IED_SERVER: readAccessControlObject: %s\n", variableIdOrig);

    char variableId[129];

    strncpy(variableId, variableIdOrig, 128);
    variableId[128] = 0;

    char* separator = strchr(variableId, '$');

    if (separator == NULL)
        return NULL;

    *separator = 0;

    char* lnName = variableId;

    if (lnName == NULL)
        return NULL;

    char* objectName = MmsMapping_getNextNameElement(separator + 1);

    if (objectName == NULL)
        return NULL;

    char* varName =  MmsMapping_getNextNameElement(objectName);

    if (varName != NULL) {

        bool foundVar = false;

        char* nextVarName = varName;

        do {
            if (doesElementEquals(varName, "Oper") ||
                doesElementEquals(varName, "SBO") ||
                doesElementEquals(varName, "SBOw") ||
                doesElementEquals(varName, "Cancel"))
            {
                *(varName - 1) = 0;
                foundVar = true;
                break;
            }

            nextVarName  = MmsMapping_getNextNameElement(varName);

            if (nextVarName != NULL)
                varName = nextVarName;

        } while (nextVarName != NULL);

        if (foundVar == false)
            varName = NULL;
    }

    if (DEBUG_IED_SERVER)
        printf("IED_SERVER: read_access control object: objectName: (%s) varName: (%s)\n", objectName, varName);

    ControlObject* controlObject = Control_lookupControlObject(self, domain, lnName, objectName);

    if (controlObject != NULL) {

        initialize(controlObject);

        if (varName != NULL) {
            if (strcmp(varName, "Oper") == 0)
                value = ControlObject_getOper(controlObject);
            else if (strcmp(varName, "SBOw") == 0)
                value = ControlObject_getSBOw(controlObject);
            else if (strcmp(varName, "SBO") == 0) {
                if (controlObject->ctlModel == 2) {

                    uint64_t currentTime = Hal_getTimeInMs();

                    value = controlObject->emptyString;

                    checkSelectTimeout(controlObject, currentTime);

                    if (getState(controlObject) == STATE_UNSELECTED) {
                        CheckHandlerResult checkResult = CONTROL_ACCEPTED;

                        if (controlObject->checkHandler != NULL) { /* perform operative tests */
                            checkResult = controlObject->checkHandler(
                                    controlObject->checkHandlerParameter, NULL, false, false,
                                    (ClientConnection) connection);
                        }

                        if (checkResult == CONTROL_ACCEPTED) {
                            selectObject(controlObject, currentTime, connection);
                            value = ControlObject_getSBO(controlObject);
                        }
                    }

                }
                else {
                    if (DEBUG_IED_SERVER)
                        printf("IED_SERVER: select not applicable for control model %i\n", controlObject->ctlModel);

                    value = ControlObject_getSBO(controlObject);
                }
            }

            else if (strcmp(varName, "Cancel") == 0)
                value = ControlObject_getCancel(controlObject);
            else {
                value = MmsValue_getSubElement(ControlObject_getMmsValue(controlObject),
                        ControlObject_getTypeSpec(controlObject), varName);
            }
        }
        else
            value = ControlObject_getMmsValue(controlObject);
    }

    return value;
}
예제 #22
0
파일: control.c 프로젝트: brennane/gridpot
MmsDataAccessError
Control_writeAccessControlObject(MmsMapping* self, MmsDomain* domain, char* variableIdOrig,
        MmsValue* value, MmsServerConnection connection)
{
    MmsDataAccessError indication = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED;

    if (DEBUG_IED_SERVER)
        printf("IED_SERVER: writeAccessControlObject: %s\n", variableIdOrig);

    char variableId[65];

    strncpy(variableId, variableIdOrig, 64);
    variableId[64] = 0;

    char* separator = strchr(variableId, '$');

    if (separator == NULL)
        goto free_and_return;

    *separator = 0;

    char* lnName = variableId;

    if (lnName == NULL)
        goto free_and_return;

    char* objectName = MmsMapping_getNextNameElement(separator + 1);

    if (objectName == NULL)
        goto free_and_return;

    char* varName =  MmsMapping_getNextNameElement(objectName);

    if (varName != NULL) {

        bool foundVar = false;

        char* nextVarName = varName;

        do {
            if (doesElementEquals(varName, "Oper") ||
                doesElementEquals(varName, "SBO") ||
                doesElementEquals(varName, "SBOw") ||
                doesElementEquals(varName, "Cancel"))
            {
                *(varName - 1) = 0;
                foundVar = true;
                break;
            }

            nextVarName  = MmsMapping_getNextNameElement(varName);

            if (nextVarName != NULL)
                varName = nextVarName;

        } while (nextVarName != NULL);

        if (foundVar == false)
            varName = NULL;
    }


    if (DEBUG_IED_SERVER)
        printf("IED_SERVER: write access control: objectName: (%s) varName: (%s)\n", objectName, varName);


    if (varName == NULL) {
        indication = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED;
        goto free_and_return;
    }

    ControlObject* controlObject = Control_lookupControlObject(self, domain, lnName, objectName);

    if (controlObject == NULL) {
        indication = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED;
        goto free_and_return;
    }

    initialize(controlObject);

    if (strcmp(varName, "SBOw") == 0) { /* select with value */

        if (controlObject->ctlModel == 4) {

            MmsValue* ctlVal = getCtlVal(value);

            if (ctlVal != NULL) {

                MmsValue* ctlNum = getOperParameterCtlNum(value);
                MmsValue* origin = getOperParameterOrigin(value);
                MmsValue* check = getOperParameterCheck(value);
                MmsValue* test = getOperParameterTest(value);

                if (checkValidityOfOriginParameter(origin) == false) {
                    indication = DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID;
                    goto free_and_return;
                }

                uint64_t currentTime = Hal_getTimeInMs();

                checkSelectTimeout(controlObject, currentTime);

                int state = getState(controlObject);

                if (state != STATE_UNSELECTED) {
                    indication = DATA_ACCESS_ERROR_TEMPORARILY_UNAVAILABLE;

                    if (connection != controlObject->mmsConnection)
                        ControlObject_sendLastApplError(controlObject, connection, "SBOw", 0,
                                ADD_CAUSE_LOCKED_BY_OTHER_CLIENT, ctlNum, origin, true);
                    else
                        ControlObject_sendLastApplError(controlObject, connection, "SBOw", 0,
                                ADD_CAUSE_OBJECT_ALREADY_SELECTED, ctlNum, origin, true);

                    if (DEBUG_IED_SERVER)
                        printf("SBOw: select failed!\n");
                }
                else {

                    CheckHandlerResult checkResult = CONTROL_ACCEPTED;

                    bool interlockCheck = MmsValue_getBitStringBit(check, 1);

                    bool testCondition = MmsValue_getBoolean(test);

                    if (controlObject->checkHandler != NULL) { /* perform operative tests */

                        ClientConnection clientConnection = private_IedServer_getClientConnectionByHandle(self->iedServer,
                                                    connection);

                        checkResult = controlObject->checkHandler(
                                controlObject->checkHandlerParameter, ctlVal, testCondition, interlockCheck,
                                clientConnection);
                    }

                    if (checkResult == CONTROL_ACCEPTED) {
                        selectObject(controlObject, currentTime, connection);

                        updateControlParameters(controlObject, ctlVal, ctlNum, origin);

                        indication = DATA_ACCESS_ERROR_SUCCESS;

                        if (DEBUG_IED_SERVER)
                            printf("SBOw: selected successful\n");
                    }
                    else {
                        indication = getDataAccessErrorFromCheckHandlerResult(checkResult);

                        ControlObject_sendLastApplError(controlObject, connection, "SBOw", 0,
                                ADD_CAUSE_SELECT_FAILED, ctlNum, origin, true);

                        if (DEBUG_IED_SERVER)
                            printf("SBOw: select rejected by application!\n");
                    }
                }
            }
            else {
                indication = DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID;
            }
        }
        else {
            indication = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED;
            goto free_and_return;
        }
    }
    else if (strcmp(varName, "Oper") == 0) {
        MmsValue* ctlVal = getCtlVal(value);
        MmsValue* test = getOperParameterTest(value);
        MmsValue* ctlNum = getOperParameterCtlNum(value);
        MmsValue* origin = getOperParameterOrigin(value);
        MmsValue* check = getOperParameterCheck(value);
        MmsValue* timeParameter = getOperParameterTime(value);

        if ((ctlVal == NULL) || (test == NULL) || (ctlNum == NULL) || (origin == NULL) || (check == NULL)
                || (timeParameter == NULL)) {
            indication = DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID;
            goto free_and_return;
        }

        if (checkValidityOfOriginParameter(origin) == false) {
            indication = DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID;
            goto free_and_return;
        }

        uint64_t currentTime = Hal_getTimeInMs();

        checkSelectTimeout(controlObject, currentTime);

        int state = getState(controlObject);

        if (state == STATE_WAIT_FOR_ACTIVATION_TIME) {
            indication = DATA_ACCESS_ERROR_TEMPORARILY_UNAVAILABLE;

            ControlObject_sendLastApplError(controlObject, connection, "Oper",
                    CONTROL_ERROR_NO_ERROR, ADD_CAUSE_COMMAND_ALREADY_IN_EXECUTION,
                        ctlNum, origin, true);

            goto free_and_return;
        }
        else if (state == STATE_READY) {

            bool interlockCheck = MmsValue_getBitStringBit(check, 1);
            bool synchroCheck = MmsValue_getBitStringBit(check, 0);

            bool testCondition = MmsValue_getBoolean(test);

            controlObject->testMode = testCondition;

            if ((controlObject->ctlModel == 2) || (controlObject->ctlModel == 4)) {
                if (controlObject->mmsConnection != connection) {
                    indication = DATA_ACCESS_ERROR_TEMPORARILY_UNAVAILABLE;
                    if (DEBUG_IED_SERVER)
                        printf("Oper: operate from wrong client connection!\n");
                    goto free_and_return;
                }

                if (controlObject->ctlModel == 4) { /* select-before-operate with enhanced security */
                    if ((MmsValue_equals(ctlVal, controlObject->ctlVal) &&
                         MmsValue_equals(origin, controlObject->origin) &&
                         MmsValue_equals(ctlNum, controlObject->ctlNum)) == false)
                    {

                        indication = DATA_ACCESS_ERROR_TYPE_INCONSISTENT;
                        ControlObject_sendLastApplError(controlObject, connection, "Oper",
                                CONTROL_ERROR_NO_ERROR, ADD_CAUSE_INCONSISTENT_PARAMETERS,
                                    ctlNum, origin, true);

                        goto free_and_return;
                    }
                }
            }

            updateControlParameters(controlObject, ctlVal, ctlNum, origin);

            MmsValue* operTm = getOperParameterOperTime(value);

            if (operTm != NULL) {
                controlObject->operateTime = MmsValue_getUtcTimeInMs(operTm);

                if (controlObject->operateTime != 0) {
                    controlObject->timeActivatedOperate = true;
                    controlObject->synchroCheck = synchroCheck;
                    controlObject->interlockCheck = interlockCheck;
                    controlObject->mmsConnection = connection;

                    initiateControlTask(controlObject);

                    setState(controlObject, STATE_WAIT_FOR_ACTIVATION_TIME);

                    if (DEBUG_IED_SERVER)
                        printf("Oper: activate time activated control\n");

                    indication = DATA_ACCESS_ERROR_SUCCESS;
                }
            }

            MmsValue_update(controlObject->oper, value);

            if (controlObject->timeActivatedOperate == false) {

                CheckHandlerResult checkResult = CONTROL_ACCEPTED;

                if (controlObject->checkHandler != NULL) { /* perform operative tests */

                    ClientConnection clientConnection = private_IedServer_getClientConnectionByHandle(self->iedServer,
                            connection);

                    checkResult = controlObject->checkHandler(
                            controlObject->checkHandlerParameter, ctlVal, testCondition, interlockCheck,
                            clientConnection);
                }


                if (checkResult == CONTROL_ACCEPTED) {
                    indication = DATA_ACCESS_ERROR_NO_RESPONSE;

                    controlObject->mmsConnection = connection;

                    controlObject->operateInvokeId = MmsServerConnection_getLastInvokeId(connection);

                    setState(controlObject, STATE_WAIT_FOR_EXECUTION);

                    initiateControlTask(controlObject);

#if (CONFIG_MMS_THREADLESS_STACK == 1)
                    //TODO call this in single threaded version to increase response time!?
                    //executeControlTask(controlObject);
#endif

                }
                else {
                    indication = getDataAccessErrorFromCheckHandlerResult(checkResult);

                    abortControlOperation(controlObject);
                }
            }

        }
        else if (state == STATE_UNSELECTED) {
            if (DEBUG_IED_SERVER)
                printf("IED_SERVER: Oper failed - control not selected!\n");

            indication = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED;
            ControlObject_sendLastApplError(controlObject, connection, "Oper",
                    CONTROL_ERROR_NO_ERROR, ADD_CAUSE_OBJECT_NOT_SELECTED,
                        ctlNum, origin, true);

            goto free_and_return;
        }
    }
    else if (strcmp(varName, "Cancel") == 0) {
        if (DEBUG_IED_SERVER)
            printf("IED_SERVER: control received cancel!\n");

        int state = getState(controlObject);

        MmsValue* ctlNum = getCancelParameterCtlNum(value);
        MmsValue* origin = getCancelParameterOrigin(value);

        if ((ctlNum == NULL) || (origin == NULL)) {
            indication = DATA_ACCESS_ERROR_TYPE_INCONSISTENT;
            if (DEBUG_IED_SERVER)
                printf("IED_SERVER: Invalid cancel message!\n");
            goto free_and_return;
        }

        if ((controlObject->ctlModel == 2) || (controlObject->ctlModel == 4)) {
            if (state != STATE_UNSELECTED) {
                if (controlObject->mmsConnection == connection) {
                    indication = DATA_ACCESS_ERROR_SUCCESS;
                    setState(controlObject, STATE_UNSELECTED);
                    goto free_and_return;
                }
                else {
                    indication = DATA_ACCESS_ERROR_TEMPORARILY_UNAVAILABLE;
                    ControlObject_sendLastApplError(controlObject, connection, "Cancel",
                            CONTROL_ERROR_NO_ERROR, ADD_CAUSE_LOCKED_BY_OTHER_CLIENT,
                                ctlNum, origin, true);
                }
            }
        }

        if (controlObject->timeActivatedOperate) {
            controlObject->timeActivatedOperate = false;
            abortControlOperation(controlObject);
            indication = DATA_ACCESS_ERROR_SUCCESS;
            goto free_and_return;
        }
    }

free_and_return:

    return indication;
}
void SelectionHandler::selectAtPoint(WebCore::IntPoint& location)
{
    // selectAtPoint API currently only supports WordGranularity but may be extended in the future.
    selectObject(location, WordGranularity);
}
예제 #24
0
bool addXData()
{
	Acad::ErrorStatus es, esTmp;
	CLogger::Print(_T("*Call: addXData()"));

	//------------
	// Require to select an entity.
	AcDbObject* pObj = selectObject(AcDb::kForRead);
	if (!pObj) {
		CLogger::Print(_T("*Exit: addXData() - Khong chon duoc object!"));
		return false;
	}

	//------------
	// Require to enter the application name, then require to enter its string value.
	ACHAR appName[133], resString[133];
	appName[0] = resString[0] = L'\0';
	acedGetString(NULL, ACRX_T("\nEnter application name: "), appName);
	acedGetString(NULL, ACRX_T("\nEnter string to be added: "), resString);

	CLogger::Print(_T("Inform: Found out application name '%s'!"), appName);
	struct resbuf * pRb;
	struct resbuf * pTemp;
	pRb = pObj->xData(appName);

	if (pRb) {
		// If the appname is existing! Seek to the tail of resbuf link list.
		CLogger::Print(_T("Inform: Found out application name '%s' - Seek to the end of resbuf link list."), appName);
		for (pTemp = pRb; pTemp->rbnext; pTemp = pTemp->rbnext) {}
	} else {
		// If the appname is not existing! Register a new application name.
		CLogger::Print(_T("Inform: The application name %s is not existing, register this application name!"), appName);
		acdbRegApp(appName);

		// Then create new resbuf to copy the application name into it.
		pRb = acutNewRb(AcDb::kDxfRegAppName);
		pTemp = pRb;
		pTemp->resval.rstring = (ACHAR*) malloc((lstrlen(appName) + 1) * sizeof(ACHAR));
		lstrcpy(pTemp->resval.rstring, appName);
	}

	//------------
	// Create new resbuf at the tail of the link list, then copy the value string into it.
	pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString);
	pTemp = pTemp->rbnext;
	pTemp->resval.rstring = (ACHAR*) malloc((lstrlen(resString) + 1) * sizeof(ACHAR));
	lstrcpy(pTemp->resval.rstring, resString);

	CLogger::Print(_T("Inform: Upgrade object opening!"));
	if (Acad::eOk != (es = pObj->upgradeOpen())) {
		CLogger::Print(_T("*Exit: addXData() - Fail to upgrade opening object!"));
		pObj->close();
		acutRelRb(pRb);
		return false;
	}

	//------------
	// Set object's xData.
	pObj->setXData(pRb);
	pObj->close();
	acutRelRb(pRb); // remember to release resbuf after using
	CLogger::Print(_T("*Exit: addXData()!"));
	return true;
}
void 
addXdata() 
{
    AcDbObject* pObj = selectObject(AcDb::kForRead);
    if (!pObj) {
        acutPrintf(_T("Error selecting object\n"));
        return;
    }

    
    // Get the application name and string to be added to
    // xdata.
    //
    TCHAR appName[132], resString[200];
    appName[0] = resString[0] = _T('\0');

    acedGetString(NULL, _T("Enter application name: "),
        appName);
    acedGetString(NULL, _T("Enter string to be added: "),
        resString);

    
    struct  resbuf  *pRb, *pTemp;
    
    pRb = pObj->xData(appName);

    if (pRb != NULL) {

        // If xdata is present, then walk to the
        // end of the list.
        //
        for (pTemp = pRb; pTemp->rbnext != NULL;
                pTemp = pTemp->rbnext)
                { ; }
    } else {
        // If xdata is not present, register the application
        // and add appName to the first resbuf in the list.
        // Notice that there is no -3 group as there is in
        // AutoLISP. This is ONLY the xdata so
        // the -3 xdata-start marker isn't needed.
        // 
        acdbRegApp(appName);

        pRb = acutNewRb(AcDb::kDxfRegAppName);
        pTemp = pRb;
        const size_t nSize = _tcslen(appName) + 1;
        pTemp->resval.rstring
            = (TCHAR*) malloc(nSize * sizeof(TCHAR));
        errno_t err = _tcscpy_s(pTemp->resval.rstring, nSize, appName);
        assert(err == 0);
    }

    // Add user-specified string to the xdata.
    //
    pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString);
    pTemp = pTemp->rbnext;
    const size_t nSize = _tcslen(resString) + 1;
    pTemp->resval.rstring
        = (TCHAR*) malloc(nSize * sizeof(TCHAR));
    errno_t err = _tcscpy_s(pTemp->resval.rstring, nSize, resString);
    assert(err == 0);

    // The following code shows the use of upgradeOpen()
    // to change the entity from read to write.
    //
    pObj->upgradeOpen();
    pObj->setXData(pRb);
    
    pObj->close();
    acutRelRb(pRb);
}
PropEditorWidget::PropEditorWidget(ObjTreeQtModel* aObjTreeMdl, QWidget * parent, Qt::WindowFlags flags) :
                                   QDockWidget(parent, flags),
                                   Ui::RKPropEditorWidget(),
                                   mdl(aObjTreeMdl->get_object_graph(),aObjTreeMdl->get_root_node()),
                                   delegate(&mdl)
{
  setupUi(this);
  this->tableView->setModel(&mdl);
  this->tableView->setRootIndex(QModelIndex());
  this->tableView->setItemDelegate(&delegate);
  this->tableTab->setAttribute(Qt::WA_AlwaysShowToolTips, true);
  this->sourceTab->setAttribute(Qt::WA_AlwaysShowToolTips, true);
  
  connect(aObjTreeMdl, SIGNAL(objectNodeSelected(serialization::object_node_desc)), &mdl, SLOT(selectObject(serialization::object_node_desc)));
  connect(&mdl, SIGNAL(objectTreeChanged()), aObjTreeMdl, SLOT(treeChanged()));

  connect(&mdl, SIGNAL(objectNameChanged(std::string)), this, SLOT(objNameChanged(std::string)));
  connect(&mdl, SIGNAL(sourceDataChanged()), this, SLOT(xmlSrcChanged()));
  connect(this, SIGNAL(editedXMLSrc(std::string)), &mdl, SLOT(sourceDataEdited(std::string)));
  
  connect(this->applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClick()));
  connect(this->cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClick()));
  
  connect(this->textEdit, SIGNAL(textChanged()), this, SLOT(onTextChanged()));
};
void
CQIllustratorAlignToolbar::
addWidgets()
{
  QBoxLayout *layout = qobject_cast<QBoxLayout *>(CQIllustratorToolbar::layout());

  QGridLayout *grid = new QGridLayout;
  grid->setMargin(0); grid->setSpacing(2);

  layout->addLayout(grid);

  //-----

  QTabWidget *tab = new QTabWidget;

  QFont font = tab->font();

  font.setPointSizeF(font.pointSizeF()*0.7);

  tab->setFont(font);

  //------

  alignw_ = new CQAlignButtons;

  tab->addTab(alignw_, "Align");

  connect(alignw_, SIGNAL(alignLeft()), this, SIGNAL(alignLeft()));
  connect(alignw_, SIGNAL(alignBottom()), this, SIGNAL(alignBottom()));
  connect(alignw_, SIGNAL(alignRight()), this, SIGNAL(alignRight()));
  connect(alignw_, SIGNAL(alignTop()), this, SIGNAL(alignTop()));
  connect(alignw_, SIGNAL(alignHorizontal()), this, SIGNAL(alignHorizontal()));
  connect(alignw_, SIGNAL(alignVertical()), this, SIGNAL(alignVertical()));

  connect(alignw_, SIGNAL(alignLeftPreview()), this, SIGNAL(alignLeftPreview()));
  connect(alignw_, SIGNAL(alignBottomPreview()), this, SIGNAL(alignBottomPreview()));
  connect(alignw_, SIGNAL(alignRightPreview()), this, SIGNAL(alignRightPreview()));
  connect(alignw_, SIGNAL(alignTopPreview()), this, SIGNAL(alignTopPreview()));
  connect(alignw_, SIGNAL(alignHorizontalPreview()), this, SIGNAL(alignHorizontalPreview()));
  connect(alignw_, SIGNAL(alignVerticalPreview()), this, SIGNAL(alignVerticalPreview()));

  connect(alignw_, SIGNAL(alignPreviewClear()), this, SIGNAL(alignPreviewClear()));

  //------

  distw_ = new CQDistButtons;

  tab->addTab(distw_, "Distribute");

  //------

  spreadw_ = new CQSpreadButtons;

  tab->addTab(spreadw_, "Spread");

  //------

  grid->addWidget(tab, 0, 0, 2, 1);

  //------

  QLabel *olabel = new QLabel("<small><b>Offset</b></small>");

  offset_ = new CQRealEdit(0.0);

  offset_->setFocusPolicy(Qt::ClickFocus);

  grid->addWidget(olabel , 0, 1);
  grid->addWidget(offset_, 1, 1);

  //------

  anchor_ = new CQAlignAnchor;

  connect(anchor_, SIGNAL(selectObject()), this, SIGNAL(selectAnchorObject()));
  connect(anchor_, SIGNAL(selectPosition()), this, SIGNAL(selectAnchorPosition()));
  connect(anchor_, SIGNAL(cancelSelect()), this, SIGNAL(cancelSelectAnchor()));

  grid->addWidget(anchor_, 0, 2, 2, 1);

  //------

  grid->setColumnStretch(3, 1);
}