void RenderLayersProg::determineResolution(unsigned int resolution[2], unsigned int /*preferredResolution*/[2]) { Scene *sce = this->getScene(); Render *re = (sce) ? RE_GetSceneRender(sce) : NULL; RenderResult *rr = NULL; resolution[0] = 0; resolution[1] = 0; if (re) { rr = RE_AcquireResultRead(re); } if (rr) { ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&sce->view_layers, getLayerId()); if (view_layer) { RenderLayer *rl = RE_GetRenderLayer(rr, view_layer->name); if (rl) { resolution[0] = rl->rectx; resolution[1] = rl->recty; } } } if (re) { RE_ReleaseResult(re); } }
/** * Initializes the text data of the text label of this dimension. * The text data is created at 0/0 at an angle or 0. Moving the * label to the right position at the right angle is up to the * particular dimension implementation. */ void RDimensionData::initTextData() const { double dimtxt = getDimtxt(); QString label = getMeasurement(); // TODO: fontName property takes precedence textData = RTextData(RVector(0,0), // position RVector(0,0), // alignment point dimtxt, // text height 0.0, RS::VAlignMiddle, RS::HAlignCenter, RS::LeftToRight, RS::Exact, 1.0, label, //fontName, (document==NULL || document->getDimensionFont().isEmpty()) ? "Standard" : document->getDimensionFont(), false, false, 0.0, false // not simple (diameter signs, stacked text, ...) ); textData.setDocument(document); textData.setLayerId(getLayerId()); textData.setBlockId(getBlockId()); textData.setColor(getColor()); textData.setLineweight(getLineweight()); textData.setSelected(isSelected()); textData.setDimensionLabel(true); //qDebug() << "label color: " << textData.getColor(); //qDebug() << "textData: " << textData; dirty = true; }
void RenderLayersBaseProg::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { Scene *sce = this->getScene(); Render *re = (sce) ? RE_GetRender(sce->id.name) : NULL; RenderResult *rr = NULL; resolution[0] = 0; resolution[1] = 0; if (re) rr = RE_AcquireResultRead(re); if (rr) { SceneRenderLayer *srl = (SceneRenderLayer *)BLI_findlink(&sce->r.layers, getLayerId()); if (srl) { RenderLayer *rl = RE_GetRenderLayer(rr, srl->name); if (rl && rl->rectf) { resolution[0] = rl->rectx; resolution[1] = rl->recty; } } } if (re) RE_ReleaseResult(re); }
void RenderLayersBaseProg::initExecution() { Scene *scene = this->getScene(); Render *re = (scene) ? RE_GetRender(scene->id.name) : NULL; RenderResult *rr = NULL; if (re) rr = RE_AcquireResultRead(re); if (rr) { SceneRenderLayer *srl = (SceneRenderLayer *)BLI_findlink(&scene->r.layers, getLayerId()); if (srl) { RenderLayer *rl = RE_GetRenderLayer(rr, srl->name); if (rl && rl->rectf) { this->m_inputBuffer = RE_RenderLayerGetPass(rl, this->m_renderpass); if (this->m_inputBuffer == NULL && this->m_renderpass == SCE_PASS_COMBINED) { this->m_inputBuffer = rl->rectf; } } } } if (re) { RE_ReleaseResult(re); re = NULL; } }
void RenderLayersProg::initExecution() { Scene *scene = this->getScene(); Render *re = (scene) ? RE_GetSceneRender(scene) : NULL; RenderResult *rr = NULL; if (re) { rr = RE_AcquireResultRead(re); } if (rr) { ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&scene->view_layers, getLayerId()); if (view_layer) { RenderLayer *rl = RE_GetRenderLayer(rr, view_layer->name); if (rl) { this->m_inputBuffer = RE_RenderLayerGetPass( rl, this->m_passName.c_str(), this->m_viewName); } } } if (re) { RE_ReleaseResult(re); re = NULL; } }
static void garmin_read_process(struct garmin_data *garmin_data_p, unsigned char *data, unsigned data_length, int bulk_data) { unsigned long flags; if (garmin_data_p->flags & FLAGS_DROP_DATA) { /* abort-transfer cmd is actice */ dev_dbg(&garmin_data_p->port->dev, "%s - pkt dropped\n", __func__); } else if (garmin_data_p->state != STATE_DISCONNECTED && garmin_data_p->state != STATE_RESET) { /* if throttling is active or postprecessing is required put the received data in the input queue, otherwise send it directly to the tty port */ if (garmin_data_p->flags & FLAGS_QUEUING) { pkt_add(garmin_data_p, data, data_length); } else if (bulk_data || getLayerId(data) == GARMIN_LAYERID_APPL) { spin_lock_irqsave(&garmin_data_p->lock, flags); garmin_data_p->flags |= APP_RESP_SEEN; spin_unlock_irqrestore(&garmin_data_p->lock, flags); if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { pkt_add(garmin_data_p, data, data_length); } else { send_to_tty(garmin_data_p->port, data, data_length); } } /* ignore system layer packets ... */ } }
void RStorage::setCurrentLayer(const QString& layerName, RTransaction* transaction) { bool useLocalTransaction; QSharedPointer<RDocumentVariables> docVars = startDocumentVariablesTransaction(transaction, useLocalTransaction); Q_ASSERT(!docVars.isNull()); RLayer::Id layerId = getLayerId(layerName); if (layerId == RLayer::INVALID_ID) { return; } docVars->setCurrentLayerId(layerId); endDocumentVariablesTransaction(transaction, useLocalTransaction, docVars); }
/** * Stream operator for QDebug */ void REntity::print(QDebug dbg) const { dbg.nospace() << "REntity("; RObject::print(dbg); dbg.nospace() << ", type: " << getType() << ", layerId: " << getLayerId() << ", blockId: " << getBlockId() << ", lineweight: " << getLineweight() << ", linetypeId: " << getLinetypeId() << ", color: " << getColor() << ", drawOrder: " << getDrawOrder() << ", selectionStatus: " << isSelected() << ", boundingBoxes: " << getBoundingBoxes() << ")"; }
/** * \return true if this entity can be edited (i.e. is not on a locked layer). */ bool REntity::isEditable(bool allowInvisible) const { if (getDocument()==NULL) { return true; } // entities that are not visible are never editable: if (!allowInvisible && !isVisible()) { return false; } // entities on locked layers are not editable: if (getDocument()->isLayerLocked(getLayerId())) { return false; } return true; }
/** * Stream operator for QDebug */ void REntity::print(QDebug dbg) const { dbg.nospace() << "REntity("; RObject::print(dbg); dbg.nospace() << ", type: " << getType() << ", layerId: " << getLayerId() << ", blockId: " << getBlockId() << ", parentId: " << getParentId() << ", childIds: " << getDocument()->queryChildEntities(getId()) << ", lineweight: " << getLineweight() << ", linetypeId: " << getLinetypeId() << ", linetypeScale: " << getLinetypeScale() << ", color: " << getColor() << ", drawOrder: " << getDrawOrder() << ", selectionStatus: " << isSelected() << ", boundingBoxes: " << getBoundingBoxes() << ")"; }
/** * \return true if this entity is visible (i.e. is not on a frozen layer * or in a frozen block). */ bool REntity::isVisible() const { if (getDocument()==NULL) { return true; } // check if layer is frozen: if (getDocument()->isLayerFrozen(getLayerId())) { return false; } // check if block is frozen: const RBlockReferenceEntity* blockRef = dynamic_cast<const RBlockReferenceEntity*>(this); if (blockRef!=NULL) { RBlock::Id blockId = blockRef->getReferencedBlockId(); if (blockId!=RBlock::INVALID_ID) { QSharedPointer<RBlock> block = getDocument()->queryBlockDirect(blockId); if (!block.isNull() && block->isFrozen()) { return false; } } } return true; }
static void garmin_write_bulk_callback(struct urb *urb) { struct usb_serial_port *port = urb->context; if (port) { struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer)) { if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { gsp_send_ack(garmin_data_p, ((__u8 *)urb->transfer_buffer)[4]); } } usb_serial_port_softint(port); } /* Ignore errors that resulted from garmin_write_bulk with dismiss_ack = 1 */ /* free up the transfer buffer, as usb_free_urb() does not do this */ kfree(urb->transfer_buffer); }
Group<E> Group<E>::getLayerId(const LayerId layerId) { std::vector<LayerId> aux; aux.push_back(layerId); return getLayerId(aux); }
bool RMemoryStorage::saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion, bool keepHandles) { if (object.isNull()) { qWarning() << "RMemoryStorage::saveObject: object is NULL"; return false; } //qDebug() << "saveObject: " << *object; // never allow two layers with identical names, update layer instead: QSharedPointer<RLayer> layer = object.dynamicCast<RLayer>(); if (!layer.isNull()) { RLayer::Id id = getLayerId(layer->getName()); if (id != RLayer::INVALID_ID && id != layer->getId()) { setObjectId(*layer, id); // never unprotect an existing protected layer: QSharedPointer<RLayer> existingLayer = queryLayerDirect(id); if (!existingLayer.isNull()) { if (existingLayer->isProtected()) { layer->setProtected(true); } } } } // never allow two blocks with identical names, update block instead: QSharedPointer<RBlock> block = object.dynamicCast<RBlock> (); if (!block.isNull()) { RBlock::Id id = getBlockId(block->getName()); if (id != RBlock::INVALID_ID && id != block->getId()) { setObjectId(*block, id); } } // never allow two linetypes with identical names, update linetype instead: QSharedPointer<RLinetype> linetype = object.dynamicCast<RLinetype> (); if (!linetype.isNull()) { RLinetype::Id id = getLinetypeId(linetype->getName()); if (id != RLinetype::INVALID_ID && id != linetype->getId()) { setObjectId(*linetype, id); } } // avoid block recursions: if (checkBlockRecursion) { /* QSharedPointer<RBlockReferenceEntity> blockRef = object.dynamicCast<RBlockReferenceEntity> (); if (!blockRef.isNull()) { RBlock::Id id = blockRef->getBlockId(); RBlock::Id refId = blockRef->getReferencedBlockId(); // check if block with 'id' may contain a block reference which refers to // block with 'refid': // 201308: too slow for large, complex drawings: if (checkRecursion(id, refId)) { qCritical("RMemoryStorage::saveObject: recursion found"); return false; } } */ } QSharedPointer<REntity> entity = object.dynamicCast<REntity> (); if (!entity.isNull()) { Q_ASSERT_X(!queryLayerDirect(entity->getLayerId()).isNull(), "RMemoryStrorage::saveObject", "Layer of entity is NULL"); } // assign new object ID to new objects: if (object->getId() == RObject::INVALID_ID) { setObjectId(*object, getNewObjectId()); // only set new handle if handle is not set already: if (!keepHandles || object->getHandle()==RObject::INVALID_HANDLE) { setObjectHandle(*object, getNewObjectHandle()); } // assign draw order to new entities: if (!entity.isNull() && entity->getDrawOrder()==0) { entity->setDrawOrder(getMaxDrawOrder()); setMaxDrawOrder(getMaxDrawOrder()+1); } } // TODO: save original object for rollback: //if (inTransaction) { //transactionObjectMap[object->getId()] = object; //} objectMap[object->getId()] = object; objectHandleMap[object->getHandle()] = object; if (!entity.isNull()) { entityMap[entity->getId()] = entity; blockEntityMap.insert(entity->getBlockId(), entity); setMaxDrawOrder(qMax(entity->getDrawOrder()+1, getMaxDrawOrder())); } if (!layer.isNull()) { layerMap[object->getId()] = layer; } if (!block.isNull()) { blockMap[object->getId()] = block; } if (!linetype.isNull()) { linetypeMap[object->getId()] = linetype; } QSharedPointer<RDocumentVariables> docVars = object.dynamicCast<RDocumentVariables> (); if (!docVars.isNull()) { documentVariables = docVars; } return true; }
bool RMemoryStorage::saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion, bool keepHandles) { if (object.isNull()) { return false; } // never allow two layers with identical names, update layer instead: QSharedPointer<RLayer> layer = object.dynamicCast<RLayer>(); if (!layer.isNull()) { RLayer::Id id = getLayerId(layer->getName()); if (id != RLayer::INVALID_ID) { setObjectId(*layer, id); } } // never allow two blocks with identical names, update block instead: QSharedPointer<RBlock> block = object.dynamicCast<RBlock> (); if (!block.isNull()) { RBlock::Id id = getBlockId(block->getName()); if (id != RBlock::INVALID_ID) { setObjectId(*block, id); } } // avoid block recursions: if (checkBlockRecursion) { /* QSharedPointer<RBlockReferenceEntity> blockRef = object.dynamicCast<RBlockReferenceEntity> (); if (!blockRef.isNull()) { RBlock::Id id = blockRef->getBlockId(); RBlock::Id refId = blockRef->getReferencedBlockId(); // check if block with 'id' may contain a block reference which refers to // block with 'refid': // 201308: too slow for large, complex drawings: if (checkRecursion(id, refId)) { qCritical("RMemoryStorage::saveObject: recursion found"); return false; } } */ } QSharedPointer<REntity> entity = object.dynamicCast<REntity> (); // assign new object ID to new objects: if (object->getId() == RObject::INVALID_ID) { setObjectId(*object, getNewObjectId()); // only set new handle if handle is not set already: if (!keepHandles || object->getHandle()==RObject::INVALID_HANDLE) { setObjectHandle(*object, getNewObjectHandle()); } // assign draw order to new entities: if (!entity.isNull()) { entity->setDrawOrder(getMaxDrawOrder()); setMaxDrawOrder(getMaxDrawOrder()+1); } } // TODO: save original object for rollback: //if (inTransaction) { //transactionObjectMap[object->getId()] = object; //} objectMap[object->getId()] = object; //QSharedPointer<REntity> entity = object.dynamicCast<REntity> (); if (!entity.isNull()) { entityMap[entity->getId()] = entity; blockEntityMap.insert(entity->getBlockId(), entity); //qDebug() << "added " << entity->getId() << " to block " << entity->getBlockId(); setMaxDrawOrder(qMax(entity->getDrawOrder()+1, getMaxDrawOrder())); } if (!layer.isNull()) { layerMap[object->getId()] = layer; } if (!block.isNull()) { blockMap[object->getId()] = block; } return true; }
static int garmin_write_bulk(struct usb_serial_port *port, const unsigned char *buf, int count, int dismiss_ack) { unsigned long flags; struct usb_serial *serial = port->serial; struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); struct urb *urb; unsigned char *buffer; int status; spin_lock_irqsave(&garmin_data_p->lock, flags); garmin_data_p->flags &= ~FLAGS_DROP_DATA; spin_unlock_irqrestore(&garmin_data_p->lock, flags); buffer = kmalloc(count, GFP_ATOMIC); if (!buffer) { dev_err(&port->dev, "out of memory\n"); return -ENOMEM; } urb = usb_alloc_urb(0, GFP_ATOMIC); if (!urb) { dev_err(&port->dev, "no more free urbs\n"); kfree(buffer); return -ENOMEM; } memcpy(buffer, buf, count); usb_serial_debug_data(&port->dev, __func__, count, buffer); usb_fill_bulk_urb(urb, serial->dev, usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress), buffer, count, garmin_write_bulk_callback, dismiss_ack ? NULL : port); urb->transfer_flags |= URB_ZERO_PACKET; if (GARMIN_LAYERID_APPL == getLayerId(buffer)) { spin_lock_irqsave(&garmin_data_p->lock, flags); garmin_data_p->flags |= APP_REQ_SEEN; spin_unlock_irqrestore(&garmin_data_p->lock, flags); if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { pkt_clear(garmin_data_p); garmin_data_p->state = STATE_GSP_WAIT_DATA; } } /* send it down the pipe */ status = usb_submit_urb(urb, GFP_ATOMIC); if (status) { dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", __func__, status); count = status; } /* we are done with this urb, so let the host driver * really free it when it is finished with it */ usb_free_urb(urb); return count; }
/* * Sends a usb packet to the tty * * Assumes, that all packages and at an usb-packet boundary. * * return <0 on error, 0 if packet is incomplete or > 0 if packet was sent */ static int gsp_send(struct garmin_data *garmin_data_p, const unsigned char *buf, int count) { struct device *dev = &garmin_data_p->port->dev; const unsigned char *src; unsigned char *dst; int pktid = 0; int datalen = 0; int cksum = 0; int i = 0; int k; dev_dbg(dev, "%s - state %d - %d bytes.\n", __func__, garmin_data_p->state, count); k = garmin_data_p->outsize; if ((k+count) > GPS_OUT_BUFSIZ) { dev_dbg(dev, "packet too large\n"); garmin_data_p->outsize = 0; return -4; } memcpy(garmin_data_p->outbuffer+k, buf, count); k += count; garmin_data_p->outsize = k; if (k >= GARMIN_PKTHDR_LENGTH) { pktid = getPacketId(garmin_data_p->outbuffer); datalen = getDataLength(garmin_data_p->outbuffer); i = GARMIN_PKTHDR_LENGTH + datalen; if (k < i) return 0; } else { return 0; } dev_dbg(dev, "%s - %d bytes in buffer, %d bytes in pkt.\n", __func__, k, i); /* garmin_data_p->outbuffer now contains a complete packet */ usb_serial_debug_data(&garmin_data_p->port->dev, __func__, k, garmin_data_p->outbuffer); garmin_data_p->outsize = 0; if (GARMIN_LAYERID_APPL != getLayerId(garmin_data_p->outbuffer)) { dev_dbg(dev, "not an application packet (%d)\n", getLayerId(garmin_data_p->outbuffer)); return -1; } if (pktid > 255) { dev_dbg(dev, "packet-id %d too large\n", pktid); return -2; } if (datalen > 255) { dev_dbg(dev, "packet-size %d too large\n", datalen); return -3; } /* the serial protocol should be able to handle this packet */ k = 0; src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; for (i = 0; i < datalen; i++) { if (*src++ == DLE) k++; } src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; if (k > (GARMIN_PKTHDR_LENGTH-2)) { /* can't add stuffing DLEs in place, move data to end of buffer ... */ dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen; memcpy(dst, src, datalen); src = dst; } dst = garmin_data_p->outbuffer; *dst++ = DLE; *dst++ = pktid; cksum += pktid; *dst++ = datalen; cksum += datalen; if (datalen == DLE) *dst++ = DLE; for (i = 0; i < datalen; i++) { __u8 c = *src++; *dst++ = c; cksum += c; if (c == DLE) *dst++ = DLE; } cksum = 0xFF & -cksum; *dst++ = cksum; if (cksum == DLE) *dst++ = DLE; *dst++ = DLE; *dst++ = ETX; i = dst-garmin_data_p->outbuffer; send_to_tty(garmin_data_p->port, garmin_data_p->outbuffer, i); garmin_data_p->pkt_id = pktid; garmin_data_p->state = STATE_WAIT_TTY_ACK; return i; }
static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count) { struct device *dev = &port->dev; int pktid, pktsiz, len; struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); __le32 *privpkt = (__le32 *)garmin_data_p->privpkt; usb_serial_debug_data(dev, __func__, count, buf); if (garmin_data_p->state == STATE_RESET) return -EIO; /* check for our private packets */ if (count >= GARMIN_PKTHDR_LENGTH) { len = PRIVPKTSIZ; if (count < len) len = count; memcpy(garmin_data_p->privpkt, buf, len); pktsiz = getDataLength(garmin_data_p->privpkt); pktid = getPacketId(garmin_data_p->privpkt); if (count == (GARMIN_PKTHDR_LENGTH+pktsiz) && GARMIN_LAYERID_PRIVATE == getLayerId(garmin_data_p->privpkt)) { dev_dbg(dev, "%s - processing private request %d\n", __func__, pktid); /* drop all unfinished transfers */ garmin_clear(garmin_data_p); switch (pktid) { case PRIV_PKTID_SET_MODE: if (pktsiz != 4) return -EINVPKT; garmin_data_p->mode = __le32_to_cpu(privpkt[3]); dev_dbg(dev, "%s - mode set to %d\n", __func__, garmin_data_p->mode); break; case PRIV_PKTID_INFO_REQ: priv_status_resp(port); break; case PRIV_PKTID_RESET_REQ: process_resetdev_request(port); break; case PRIV_PKTID_SET_DEF_MODE: if (pktsiz != 4) return -EINVPKT; initial_mode = __le32_to_cpu(privpkt[3]); dev_dbg(dev, "%s - initial_mode set to %d\n", __func__, garmin_data_p->mode); break; } return count; } } if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { return gsp_receive(garmin_data_p, buf, count); } else { /* MODE_NATIVE */ return nat_receive(garmin_data_p, buf, count); } }